[TriLUG] MySQL INSERT syntax problem

Robert Dale robdale at gmail.com
Tue Dec 5 07:44:21 EST 2006


Are you trying to insert from the select query?  I don't believe you
can use VALUES with a SELECT...
Also, you probably want to keep your select columns matched (in order
and number) with
your insert columns

INSERT IGNORE p_coin_invoices( invc_cl_id, invc_ts, invc_ts_due )
SELECT cl_id, next_billing_date, date_add(next_billing_date, INTERVAL
21 DAY) FROM cust_extract.name = p_coin_clients.cl_user_name AND
next_billing_date < '2006-12-01'

HTH

-- 
Robert Dale


On 12/4/06, Michael Rulison <13miketele at bellsouth.net> wrote:
> I am wrestling poorly with MySql syntax and something I am just overlooking.
>
> Query below has two parts: insert and select.
> Insert is to put 3 fields for about 138 records into p_coin_invoices.
> Separately, select works fine; together they do not tango.
> The DATE_ADD function has been tested separately and works.
> Error message follows the query.
> Any comments welcome.
> Thanks,
> -----------------------------------------------------------------------------
> Michael Rulison      |     919/782-9576
> 3256 Lewis Farm Road   Raleigh  NC  27607-6723
>
> -----------------------------------------------------------------------------
> ================================================
>  INSERT IGNORE p_coin_invoices( invc_cl_id, invc_ts, invc_ts_due )
> VALUES (
> cl_id, next_billing_date, date_add( next_billing_date, INTERVAL 21
> DAY )
> )
> SELECT cl_id, cl_user_name, name, next_billing_date
> FROM p_coin_clients, cust_extract
> WHERE cust_extract.name = p_coin_clients.cl_user_name
> AND next_billing_date < '2006-12-01'
>
>  MySQL said: Documentation
> #1064 - You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near 'SELECT cl_id, cl_user_name, name, next_billing_date
> FROM p_coin_clients, cust_e' at line 6
>
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ  : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
>


-- 
Robert Dale



More information about the TriLUG mailing list