Sql-server – Case statement with multiple condition

sql serversql-server-2012

when a.name and a.rownum=1 <> b.name and (b.namereason isnull or b.namereason in ('') and b.rownum=1 then a.name
when when a.name and a.rownum=1 <> b.name and (b.namereason isnotnull or b.namereason not in ('')) and b.rownum=1 then b.name
END as name

Note: I want to compare 2 tables.

A.RowNum = is take the max date

B.rownum = is take min date

I want compare the name if got update in B, then display B else display A.

I'm dealing with 10m+ records, cannot hardcode it. I need it to be working for generally.

i got error when doing something like this. error message is An expression of non-boolean type specified in a context where a condition is expected

any idea how to do something like?

Best Answer

1) The code (pseudo) you posted is so badly indented. Please fix it for readability, and you should see why the error might be arising.

a.rownum=1 <> b.name

2) Can you please explain in plain simple words and illustrate with examples?