sql case statement error

I have a case statement, however; I'm getting two erros. I can't seem to find the answer to the fix the errors.

SELECT #TMP.webid_Val = CASE #TMP.webid 
when 'NULL' then 'NOT COMPLIANT'
else 'COMPLIANT'
end
FROM #TMP

**Incorrect syntax near FROM. Expecting CONVERSATION

Incorrect syntax near =**

#TMP is the temporary table. webid is the value to be looked at for the condition webid_val is the column who's value will be changed.

Any help would be appreciated.

Answers


(The following answer assumes Sql Server) You cannot do an update with a select statement.

If you are trying to return data to a client application or user, use

SELECT webid_Val = CASE 
    WHEN #TMP.webid IS NULL then 'NOT COMPLIANT'
    ELSE 'COMPLIANT'
END
FROM #TMP

or if you're trying to update data in the original temp table, use the following:

UPDATE #tmp SET 
webid_Val = CASE 
    WHEN #TMP.webid IS NULL then 'NOT COMPLIANT'
    ELSE 'COMPLIANT'
END
FROM #TMP

It sure seems like you want to perform an UPDATE using a CASE statement the way you were will not UPDATE the data in the table

UPDATE #TMP
SET webid_Val = 
    (CASE when webid Is NULL
        then 'NOT COMPLIANT'
        else 'COMPLIANT'
        end)

If I understand your notes correctly, you are wanting to do an update statement, not a select statement. Also, null is not a string.

the below will execute the select statement if that's all you want.

select case #TMP.webid when null then 'NOT COMPLIANT'
        else 'COMPLIANT' end
from #TMP

if you want to update every row in the table:

update #TMP
set webid_Val = (case webid when null then 'NOT COMPLIANT'
            else 'COMPLIANT' end)

Need Your Help

Shall I extend the service class or just use an instance of it?

java extends

There is a StoreService in the project, which provides some methods to read from and write to a remote data store. e.g.