Search code examples
sql-servert-sql

T-SQL - Assign field to NULL in a case statement


Probably am going crazy, but I am trying to assign a field to NULL in a case statement, however, I get an error on the equals next to the NULL keyword

Here is the SQL:

SELECT CASE WHEN enq.IntField = 0 THEN enq.IntField = NULL ELSE enq.IntField END As IntField
FROM [Table]

Surely I am doing something stupid!!

Thanks in advance


Solution

  • Try this

    CASE WHEN enq.IntField = 0 THEN NULL ELSE enq.IntField END