I'm getting the error
Incorrect syntax near '='.when I use the following case statement in a view. Obviously I'm not an expert on MS SQL, but I'm curious as to why I am allowed to use the '=' sign in a preceeding statement but not in the THEN section.Help me understand what I'm doing wrong (beside everything) :cheesy:
CASE WHEN MBAL.ALCUCD = '1' AND -- ADDRESS CODE MABL.ALE2ST = '1' -- ADDRESS TYPE THEN MBDE.DEB9CD = 'NULL' AND 'B' AS ADDRESS_TYPE END
CASE is used when you want to return different values based on different conditions, such as:
select case when priority=1 then 'Low' when priority=2 then 'Med' when priority=3 then 'High' end from priorities
or the alternative
select case priority when 1 then 'Low' when 2 then 'Med' when 3 then 'High' end from priorities
I'm not sure what you're trying to do. SQL also has an IF syntax, for example:
if exists(select * from whatever)
begin
do something
end
else
begin
do something else
end
Can you give the entire SQL statement so that we can understand exactly what you're trying to do?