Solved

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

Posted on 2008-10-20
5
155 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now