I have a CTE and an update based on it.
I am testing the value of V.CreditLimit to determine if it is 1 or <>1 and need to SET the value of T.InvoicePreferences in the SET statement. I also require to test T.InvoiceEmailAddress for a NULL or empty value no matter what value V.CreditLimit returns.
The logic is if CreditLimit = 1 then InvoicePreferences are to be 'P!FE'.
If CreditLimit <> 1 AND there is an EmailAddress then InvoicePreferences to be 'EFP' ELSE if EmailAddress is NULL or empty then InvoicePreferences are to be 'P!FE'.
The value of InvoicePreferences will then be used to update the table in the SET statement.
I'm guessing the testing is done in the SELECT with the outcome passed to the SET. Just can't seem to get the syntax right.
WITH UpDateCTE AS (SELECT T.CustomerAccountName AS T01, V.CustomerAccountName AS V01, T.AccountIsOnHold AS T02, V.AccountIsOnHold AS V02,
T.CreditLimit AS T03, V.CreditLimit AS V03, T.InvoiceEmailAddress AS T04, T.InvoicePreferences AS T05
FROM SpindleCustomerPreferences AS T INNER JOIN
floyd_GetSageCustomersVw AS V ON V.SLCustomerAccountID = T.SLCustomerAccountID)
SET T01 = V01, T02 = V02, T03 = V03;