[ic] SQL INSERT

Kevin Walsh interchange-users@interchange.redhat.com
Thu Feb 7 17:47:01 2002


> [query list=1
> 	st=db
>	table=contactnotes
>	sql="INSERT INTO contactnotes (contactno, notes, source, date) values
>	(SELECT  catalogs.code, 'show catalog sent to user' , 'catalogs' , '[scratch dropdate]'
>	FROM catalogs
>	WHERE country = 'US' AND show_qty = '1' AND completed != '1')
> "]
> [/query]
>
Get rid of the "list=1" for a start.  (Nothing to do with your problem;
it is just not useful when doing an INSERT).

>
> The error file shows...
> 
> /intranet/admin/insert_contactnotes.html Bad SQL statement: Parse error near
> SELECT  catalogs.code, 'show catalog sent to user' , 'catalogs' , '20020207'
>  	FROM catalogs
>  	WHERE country = 'US' AND show_qty = '1' AND completed != '1')
> 
>  Query was: INSERT INTO contactnotes (contactno, notes, source, date) values
>  	(SELECT  catalogs.code, 'show catalog sent to user' , 'catalogs' ,
> '20020207'
> 	FROM catalogs
> 	WHERE country = 'US' AND show_qty = '1' AND completed != '1')
> 
The error file correctly shows that this is not an Interchange problem.
Instead, it is a problem with your MySQL syntax.

Have you tried running your query using an SQL command line tool?

Try this:

    INSERT INTO table1 (col1, col2, col3)
    SELECT col1, col2, col3 from table2 WHERE foo = 'bar'

Basically, remove the extra "(" and ")" you have surrounding your
SELECT.

While you are editing, you may also find it helpful to correct the
date format from your yyyymmdd to yyyy-mm-dd.

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/