In MSSQL IF ELSE is not supported inside the SQL-Query.
For a similiar behaviour you should use CASE WHEN keyword.

Sample Query

SELECT CASE 
            WHEN [Productnumber] LIKE '112%' THEN 'SOFTWARE'
			WHEN [Productnumber] LIKE '005%' THEN 'HARDWARE'
		    ELSE 'MISC' 
       END as [ProductType] 
FROM dbo.[Products]

5 thought on “How to use IF ELSE in an SQL Select query”

Leave a Reply