Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to extract a "coded date" from a string field? 4 59
SQL Server 2012 express 24 38
SQL Restore Script - Syntax Error 8 97
INSERT DATE FROM STRING COLUMN 18 56
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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