G
Guest
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' ;
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' ;