Board index » delphi » Nesting a Select query in an Insert-query

Nesting a Select query in an Insert-query

Hello,

I'm trying to insert fields returned from a query into another
table. Im using an sql-syntax like this:

INSERT INTO Table2 (Field1, Field2, Field3)
VALUES (FieldA, FieldB, FieldC)
IN (SELECT FieldA, FieldB, FieldC
FROM Table1 WHERE FieldX = 8000)

I constantly get a message "General SQL error. Missing semicolon
(;)at end of sql-statement". I add it at the end of my sql, but
still doesn't work. Also tried some different bracketing and
still no effect

What am I doing wrong here ?
thanks !

 

Re:Nesting a Select query in an Insert-query


Quote
Bart Standaert wrote in message <3ae86229$1_2@dnews>...

>I'm trying to insert fields returned from a query into another
>table. Im using an sql-syntax like this:

>INSERT INTO Table2 (Field1, Field2, Field3)
>VALUES (FieldA, FieldB, FieldC)
>IN (SELECT FieldA, FieldB, FieldC
>FROM Table1 WHERE FieldX = 8000)

INSERT INTO Table2 (Field1, Field2, Field3)
SELECT FieldA, FieldB, FieldC
FROM Table1 WHERE FieldX = 8000

You don't say what database you're using, but this will work in
Interbase and *I think* local (BDE) SQL.

--
Wayne Niddery (WinWright Inc.)
RADBooks - http://members.home.net/wniddery/RADBooks/delphibooks.html
"At the apex of every great tragedy of mankind there stands the figure
of an incorruptible altruist" - Ayn Rand

Re:Nesting a Select query in an Insert-query


Quote
>INSERT INTO Table2 (Field1, Field2, Field3)
>VALUES (FieldA, FieldB, FieldC)
>IN (SELECT FieldA, FieldB, FieldC
>FROM Table1 WHERE FieldX = 8000)

>I constantly get a message "General SQL error. Missing semicolon
>(;)at end of sql-statement". I add it at the end of my sql, but
>still doesn't work. Also tried some different bracketing and
>still no effect

Looks to me like you are missing a WHERE

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Nesting a Select query in an Insert-query


Your query sintax is invalid.

INSERT INTO Table2 (Field1, Field2, Field3)
VALUES (FieldA, FieldB, FieldC)
SELECT FieldA, FieldB, FieldC
 FROM Table1 WHERE FieldX = 8000

Will copy from one table to another but:

INSERT INTO Table2 (Field1, Field2, Field3)
VALUES (FieldA, FieldB, FieldC)
IN (SELECT FieldA, FieldB, FieldC
FROM Table1 WHERE FieldX = 8000)

Is meanless to me.

Re:Nesting a Select query in an Insert-query


"Sergio Samayoa" <serg...@terra.com.gt> schrieb im Newsbeitrag
news:3ae997fc_2@dnews...

Quote
> Your query sintax is invalid.

> INSERT INTO Table2 (Field1, Field2, Field3)
> VALUES (FieldA, FieldB, FieldC) ---------------------*)
> SELECT FieldA, FieldB, FieldC
>  FROM Table1 WHERE FieldX = 8000

> Will copy from one table to another but:

I think you doesn't need the line  " *)"    (see localSQL.hlp-file).

Hans

Re:Nesting a Select query in an Insert-query


Yes, I didn't realize.

"Hans Prasch" <hans.pra...@t-online.de> escribi en el mensaje
news:3aea05fb_2@dnews...

Quote

> "Sergio Samayoa" <serg...@terra.com.gt> schrieb im Newsbeitrag
> news:3ae997fc_2@dnews...
> > Your query sintax is invalid.

> > INSERT INTO Table2 (Field1, Field2, Field3)
> > VALUES (FieldA, FieldB, FieldC) ---------------------*)
> > SELECT FieldA, FieldB, FieldC
> >  FROM Table1 WHERE FieldX = 8000

> > Will copy from one table to another but:

> I think you doesn't need the line  " *)"    (see localSQL.hlp-file).

> Hans

Other Threads