?
Solved

SQL Server 2008 RS Syntax

Posted on 2012-03-24
2
Medium Priority
?
395 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
[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
2 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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…

762 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