Skip to content
Advertisement

Case expression with Boolean from PostgreSQL to SQL Server

I am translating a query from PostgreSQL to SQL Server. I didn’t write the query in PostgreSQL and it’s quite complicated for my knowledge so i don’t understand every piece of it.

From my understand: we are trying to find the max version from p_policy and when insurancestatus = 7 or 14 / transactiontype = CAN, we compare two dates (whose format are BIG INT).

This is the PG Query:

  1. I am used to have a where statement where I compare it to a value. I understand here from the Case statement we will have a boolean, but still that must be compared to something?

  2. Anyway the main purpose is to make it work in SQL, but I believe SQL can’t read a CASE statement where THEN is a comparison.

This is what I tried:

And then I get this error from SQL Server (which directly the last line of the current code – so after the double case statement)

Msg 4145, Level 15, State 1, Line 55
An expression of non-boolean type specified in a context where a condition is expected, near ‘AND’.

Thank you !Let me know if it is not clear

Advertisement

Answer

I think you want boolean logic. The CASE expression would translate as:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement