Solved

Trying to use an insert into statement with a stored procedure plus an additional variable

Posted on 2008-10-20
5
162 Views
Last Modified: 2012-05-05
My code currently is writing to a table in a stored procedure.  The stored procedure should call another stored procedure that then makes a single line of output, however the current stored procedure draws additional data not used in the second stored procedure which I also want to include in the write.

Below is a code snippet, here I use the insert into statement with the stored procedure.  This part works, however I wish to add on to the end of that line a single variable value.  

Any help on how to get that variable put on the end would help.  Note that I can't merely use an update to do it because there isn't a uid, or rather, the uid would be this variable I'm trying to add.

Thanks.
insert into tat_output exec sp_findtesttatcert @mindate,@maxdate,@currenttime,@currentdate,@orderdet,@ordertest,@testsite,@orderloc,@orderphy,@orderpri,@timedatetype,@pattype,@clientcode

Open in new window

0
Comment
Question by:UnderSeven
  • 3
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
randy_knight earned 250 total points
ID: 22759493
what is the primary key of tat_output?  if it is an identity column you could use SCOPE_IDENTITY() to get the PK of the row you just added, then update it.  
0
 

Author Comment

by:UnderSeven
ID: 22759519
The problem I'm having here is that a unique primary key isn't generated from the stored procedure that writes most of the data into the tat_output table.  This is because the queries run on that could return a lot of identical results.  There is nothing unique coming from the stored procedure into Tat_output.  Could I use something like an autonumber column with scope_identity() ?
0
 
LVL 4

Expert Comment

by:randy_knight
ID: 22759608
Every table should have a primary key, even if it is just a surrogate key that is not real business data.  

And yes, an Autonumber/Identity column would solve your problem.  
0
 

Author Comment

by:UnderSeven
ID: 22759660
Thanks I'll give this a try.
0
 

Author Closing Comment

by:UnderSeven
ID: 31507872
Yep, this worked perfect.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question