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
 General SQL Server Forums
 New to SQL Server Programming
 insert into 2 tables

Author  Topic 

craigmacca
Posting Yak Master

142 Posts

Posted - 2007-12-12 : 06:15:31
Hi i have a stored prodedure which inserts into a local table then inserts into a remote table this works fine, what i need to do is.

INSERT ONTO TABLE A

THEN GET THE MAX(ID) OF THE RECORD INSERTED

THEN INSERT THAT MAX(ID) INTO TABLE B

i have created a parameter called @WebID but how do i give it the value of the MAX(ID) before i insert into tableB

Many thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-12 : 06:16:48
SELECT @Webid=max(id) from tableB

and use this variable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-12 : 06:19:32
Or SELECT @WebID = SCOPE_IDENTITY()



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

- Advertisement -