Skip to content
Advertisement

SQL Case Expression Syntax?

What is the complete and correct syntax for the SQL Case expression?

Advertisement

Answer

The complete syntax depends on the database engine you’re working with:

For SQL Server:

or:

expressions, etc:

Link: CASE (Transact-SQL)

Also note that the ordering of the WHEN statements is important. You can easily write multiple WHEN clauses that overlap, and the first one that matches is used.

Note: If no ELSE clause is specified, and no matching WHEN-condition is found, the value of the CASE expression will be NULL.

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