Hi Community<BR><BR>I&#039;m writing an ASP messageboard, and I&#039;ve written a sproc for inserting a new message into SQL Server.<BR><BR>I want to return -the classical trouble- the Id of the just added message. I use @@IDENTITY just after the INSERT INTO. Here is where the problems come.<BR><BR>I also use this value to update the message&#039;s ThreadID (you know, the Id for the 1st message in a thread) if it&#039;s a new thread to his own Id.<BR><BR>Well, my sproc doesn&#039;t update the ThreadId and doesn&#039;t return anything, but it INSERTS INTO succesfully. I am wondering if there must be a certain order in a sequence of SQL statements in a sproc. First updating, then returning? Here&#039;s an overview of the code:<BR><BR>DECLARE @id int<BR>INSERT INTO ...<BR><BR>SET @id = @@IDENTITY<BR><BR>/*returns this id to the ASP page */<BR>/*I&#039;ve seen many ways to do this! */<BR>SELECT MsgId <BR>FROM Messages<BR>WHERE MsgId = @id<BR><BR>/* if ThreadId was 0, set it to the Id of the message */<BR>/* @C is the input parameter for ThreadId */<BR>IF @C IS NULL<BR><BR>UPDATE Messages<BR>SET ThreadId = @id<BR>WHERE MsgId = @id<BR><BR>set nocount on<BR>return<BR><BR><BR>I hope I&#039;ve explained myself. Any help/advice?<BR><BR>Thanks!<BR><BR>Carlos<BR><BR><BR>