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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-07-03 : 07:32:05
|
| Bharti writes "Problem definition: Search and do multiple insertsplease check my stored procedure...Two Tables.Table 1: Users has the following fieldsFieldnames PartyIdentifier ADHUserName ADHJobIDTable 2: userssystems has the following fieldsFieldnames PartyIdentifier ADHSystemID ADHSystemFormID RoleIDlikely sequence of steps 2.SEARCH1.Find the partyidentifier in the users table with ADHJobID 3 a.select PartyIdentifier,ADHJobId from Users where ADHJobID = @ADHJobID need to store partyidentifier’s. in an array-----------------------------------------------------------Do Multiple INSERT ‘s2. I need to add the searched party identifier from the previous step and associate them w/the following fields:a. Party Identifier (PI) (return partyidentifier from above)b. System Id (SI)c. Form ID (FI)d. Role ID (RI)-------------------------------------------------------------Illustrative ExampleLets assume Step one results as follows. Partyidentifier ADHJobID 100 3 101 3 102 3then associate the data with the Party identifier 101,100,102 in the table in usersystems PI SI FI RI 100 1 2 3 101 1 2 3 101 1 2 3 Please PLEASE ..see what am i doing wrong...CREATE PROCEDURE sp_insertmultiple( @ADHJobID int, @ADHSystemId int, @ADHSystemFormsId int, @RoleId int)ASSELECT PartyIdentifier, ADHJobID From Users where ADHJobID =@ADHJobIDreturn @@identitySELECT @@IDENTITY AS 'PartyIdentifier'INSERT INTO mytest(PartyIdentifier, ADHSystemId, ADHSystemFormsId, RoleId)VALUES (@@identity,@ADHSystemId, @ADHSystemFormsId, @RoleId)GO" |
|
|
dsdeming
479 Posts |
Posted - 2003-07-03 : 09:07:50
|
From BOL: quote: @@IDENTITYReturns the last-inserted identity value.
There are a couple of problems here, but the show stopper is "return @@identity". This will exit the stored procedure immediately and return the last-inserted identity value, which I don't think is what you're after.Dennis |
 |
|
|
|
|
|
|
|