Solved

SQL Server 2008 RS Syntax

Posted on 2012-03-24
2
385 Views
Last Modified: 2012-03-24
I have an insert query that reqires a lot of variables.  My Problem is after I define the fields then all the values, the last value has to be a where so I insert into the correct record.  I am sure this is something that I have just been staring at for too long.  Here is paart of the code:


INSERT INTO MainInput () VALUES (@cty, @st,@gen,@whe,@did,@bad,@rec,@che,@alc,@par,@bar,@dru,@rom,@unR,@car,@hon,@rUs,@bat,@nim,@toy,@por,@sup,@lab,@fli,@crim,@jus,@nee,@nig,@jea,@ang,@pos,@sug,@chi,@opp,@cut,@pda,@com,@vin,@lia,@dam) where ID = (@lbl)"


cmd.Parameters.AddWithValue("@dam", Data.SqlDbType.Int).Value = Me.cbDamagedGoods.Checked
cmd.Parameters.AddWithValue("@lbl", Data.SqlDbType.Int).Value = Me.tbID.Text


How do I get the last part of that insert correct it is failing on the where clause,  I removed the fields as to not make this a 8 page psot.

Thanks in advance team!
0
Comment
Question by:jaytechnology
2 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 500 total points
ID: 37761743
If you want to use a 'where' clause with an insert you have to do it as follows:

insert into MyTable select x, y, z 

Open in new window


instead of

insert into MyTable values (x, y, z)

Open in new window

0
 

Author Closing Comment

by:jaytechnology
ID: 37761763
Perfect.  Thank you sir
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Display multiple images in report 12 84
c# code 19 59
What's the difference between these two "qualifiers?" 3 32
sql query Help 12 17
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now