0

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
2
  • 1
    just remove the 2nd and 3rd SET Commented Jul 24, 2016 at 15:44
  • 2
    @Missy Remove the keyword SET from the query. Leave everything else. Commented Jul 24, 2016 at 15:47

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

It's a syntax error. You'll have to remove some keywords:

update DLprc
   set salesamt = q.salesamt,
       salestx = q.salestx,
       nsales = q.nsales
from DLprc a
inner join q on a.customer = q.customer /* You can add more predicates here, too! */

The keyword is always used once, even if there's multiple predicates (conditions). You can add more statements to any one keyword.

In order to find the cause of syntax errors, I look at how others do their syntax.

1 Comment

Your updated query is correct, but why do you still say "You'll have to use individual statements"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.