Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert Statement?

Author  Topic 

poser
Posting Yak Master

124 Posts

Posted - 2007-08-16 : 17:17:48
I was wondering if anyone can help me. I am trying to write a stored procedure that selects a documentid (unique id) from a table and inserts the output (along with other data) into another table.

This is what I have, it isn’t returning a documentid from the select. When I execute it inside of SQL Server 2005, it works fine. But when I do it in my .NET app, it says DocumentID can’t be null in ttdTheis_Author, which tells me the output param @DocumentID is not being passed to the insert sql call…any ideas?
Thanks /P


ALTER PROCEDURE [dbo].[snpAuthorInsert] (@AccessionNum varchar (9), @AuthorName varChar(100), @DocumentID int output) as

set @DocumentID = (select documentID from ttdThesisInfo where AccessionNum = @AccessionNum)

insert into ttdThesis_Author (DocumentID, Author) values (@DocumentID, @AuthorName)


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-16 : 17:23:28
We have to see the .Net code too!
ALTER PROCEDURE [dbo].[snpAuthorInsert]
(
@AccessionNum varchar (9),
@AuthorName varChar(100),
@DocumentID int output
)
as

select @DocumentID = documentID
from ttdThesisInfo
where AccessionNum = @AccessionNum

insert ttdThesis_Author
(
DocumentID,
Author
)
values (
@DocumentID,
@AuthorName
)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -