Missy Missy - 4 months ago 16
SQL Question

Error on Simple SQL Update Statement

I have a simple update statement but I am getting an error on the second SET statement: expecting ',', id, pseudocode or variable. I can't see what I am doing wrong. Please help.

update DLprc
set salesamt = q.salesamt,
set salestx = q.salestx, <<<---- error line
set nsales = q.nsales
from DLprc a
inner join q on a.customer = q.customer

Answer

You don't need to repeat SET:

update DLprc
   set salesamt = q.salesamt, 
       salestx = q.salestx,          
       nsales = q.nsales
from DLprc a
inner join q on a.customer = q.customer

I'm accustomed to the following format for UPDATE with a JOIN:

update a
   set a.salesamt = q.salesamt, 
       a.salestx = q.salestx,          
       a.nsales = q.nsales
from DLprc a
inner join q on a.customer = q.customer