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)
 stored procedure from multiple insert statements

Author  Topic 

eevans
Starting Member

48 Posts

Posted - 2009-03-23 : 10:10:25
Hello,
I have some code that looks like this...

(Insert Into Statement)
Go
(Insert Into Statement 2)
Go
(Insert Into Statement 3)

When I click 'Execute', the statements execute in consecutive order and everything's perfect.

I would like to convert this into a single stored procedure. How could I go about doing this?

Thanks!

eevans
Starting Member

48 Posts

Posted - 2009-03-23 : 10:51:44
Would it be possible to substitute BEGIN/END for GO?
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-03-23 : 11:28:48
even inside the SP the statements will be executed consecutively, however you can have them in a single transaction which can be roll back all statements together.
Go to Top of Page

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-03-23 : 12:39:46
Are the 3 inserts going into different tables?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-23 : 12:46:27
use of GO will ensure the end of one batch and start of other so if you use any variables which are declared on top it will be out of scope after first GO
Go to Top of Page

eevans
Starting Member

48 Posts

Posted - 2009-03-23 : 13:35:20
Thanks all.

Dardusky, the inserts are going into 3 different tables.

I changed GO's to BEGIN/END's and it seems to work fine.
Go to Top of Page

eevans
Starting Member

48 Posts

Posted - 2009-03-23 : 13:37:24
Also, I am not using Declare for any variables.
Go to Top of Page
   

- Advertisement -