Solved

SQL Server 2008 RS Syntax

Posted on 2012-03-24
2
388 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Viewers will learn how the fundamental information of how to create a table.

911 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

23 Experts available now in Live!

Get 1:1 Help Now