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 and Update at the same time

Author  Topic 

new_bees
Starting Member

27 Posts

Posted - 2008-05-24 : 21:01:35
Hi guys,

Can I do an Insert and Update at the same time?


Insert code:

ALTER PROCEDURE [dbo].[AddComments]

@ID int,
@Author varchar(20),
@Email varchar(50),
@Comments varchar(200)

AS

declare @ErrorCode int

SET NOCOUNT ON

INSERT INTO COMMENTS_RECIPE (ID,AUTHOR,EMAIL,COMMENTS)
VALUES(
@ID,
@Author,
@Email,
@Comments
)
set @ErrorCode = @@error

SET NOCOUNT OFF

return @ErrorCode


Update code:

Update Recipes SET TOTAL_COMMENTS = TOTAL_COMMENTS + 1 where ID = @ID



How do I place the two in stored procedure. Sorry guys for asking this silly question. I'm still learning.

Update Recipes SET TOTAL_COMMENTS = TOTAL_COMMENTS + 1 where ID = @ID

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-05-24 : 22:31:29
You can put them in single sp, check 'CREATE PROCEDURE (Transact-SQL)' in books online for samples.
Go to Top of Page

new_bees
Starting Member

27 Posts

Posted - 2008-05-28 : 14:59:54
Thanks guys,

I just need to place a semi colon to the end of the first statement.
Go to Top of Page
   

- Advertisement -