I am having a problem doing nested case statements within a select statement. The error I get is [red]"Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'WHEN'.[/red]
I have tried using IF statements in the same manner but it seems these only work in stored procedures? Is this correct? Is it possible to do nested when's inside case statements? Can I use an IF Else statement if this is only a SQL QUERY and not a procedure?
Incorrect syntax near the keyword 'WHEN'.[/red]
Code:
SELECT
Sales.OrderID,
Buyers.eUserid,
Buyers.Email,
CASE
WHEN Addresses.Company IS NULL OR Addresses.Company = '' THEN
WHEN RTRIM(LTRIM(Addresses.FirstName)) IS NULL THEN
RTRIM(LTRIM(Adresses.LastName)) AS CompanyOrName,
ELSE
RTRIM(LTRIM(Addresses.FirstName)) & ' ' & RTRIM(LTRIM(Adresses.LastName)) AS CompanyOrName,
ELSE
Addresses.Company AS CompanyOrName,
END
...
FROM ...
...
I have tried using IF statements in the same manner but it seems these only work in stored procedures? Is this correct? Is it possible to do nested when's inside case statements? Can I use an IF Else statement if this is only a SQL QUERY and not a procedure?