Solved

SQL Server 2008 RS Syntax

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

726 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