List:General Discussion« Previous MessageNext Message »
From:SGreen Date:August 30 2005 8:22pm
Subject:Re: Insert Into problem
View as plain text  
"Ed Reed" <EReed@stripped> wrote on 08/30/2005 04:08:57 PM:

> Can anyone please tell me why this fails, I've done this type of 
> thing before without a problem
> 
> Insert Into tbl1 Select 10306, fld2, fld3, fld4 From tbl1 Where 
fld1=8114
> 
> 
> tbl1 has five fields all ints with fld5 being the autoincrement index.
> 
> I've also tried it as,
> 
> Insert Into tbl1 (fld1, fld2, fld3, fld4)
> Values(Select 10306, fld2, fld3, fld4 From tbl1 Where fld1=8114)
> 
> 
> I think its obvious what I want but just in case, I want to 
> duplicate all the records where fld1 matches my value and assign all
> the duplicate records a new value for fld1. When I do it the first 
> way I get a "Column Count doesn't match value count at row 1" error.
> When I do it the second way I just get a syntax error.
> 
> Thanks!
> 

The correct syntax for the second method doesn't use "VALUES()". I would 
always use this form if I were going to exclude any columns from receiving 
data. It's just safer and relies less on the SQL engine to correctly 
divine what it is you want to do.

Insert Into tbl1 (fld1, fld2, fld3, fld4)
Select 10306, fld2, fld3, fld4 From tbl1 Where fld1=8114;

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine
Thread
Insert Into problemEd Reed30 Aug
  • Re: Insert Into problemEamon Daly30 Aug
  • Re: Insert Into problemSGreen30 Aug
Re: Insert Into problemEd Reed30 Aug