Errors in Passthrough query

R

richardb

I am trying to update an SQL table using a pass through query. I want to
populate two of the fields conditionally, depending on the Source of Payment
and I am using IF...THEN...ELSE for the first time. I get errors back when I
try to run this. I get "Error near IF" and "Error on line 4 near p". I cannot
figure out my errors and wonder if anyone can help me. The script is:

DELETE tblSuspendedPayments
INSERT INTO tblSuspendedPayments (category, FinanceClass, ProviderCode,
PatPaid, InsPaid) SELECT f.category, p.FinanceClass, p.ProviderCode,
IF source_of_payment = '1'
BEGIN
p.amount_of_payment As PatPaid, 0 AS InsPaid
END
ELSE
BEGIN
0 As PatPaid, p. amount_of_payment AS InsPaid
END
FROM Payments p INNER JOIN FinanceClass f ON p.FinanceClass = f.FinanceClass
WHERE suspended = 'S' ;
 
R

richardb

Note space in "p. amount_of_payment " is NOT the problem. Space was not there
when tested this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top