Solved

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

Posted on 2008-10-20
5
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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