SQL Server - If condition within select query - Asked By remya on 13-Jul-12 02:58 AM

Sathish S replied to remya on 13-Jul-12 07:27 AM
You can use equivalent Case statement in sql

eg
1. USE AdventureWorks2012;
GO
SELECT   ProductNumber, Category =
      CASE ProductLine
         WHEN 'R' THEN 'Road'
         WHEN 'M' THEN 'Mountain'
         WHEN 'T' THEN 'Touring'
         WHEN 'S' THEN 'Other sale items'
         ELSE 'Not for sale'
      END,
   Name
FROM Production.Product
ORDER BY ProductNumber;
GO

http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/ 
Jitendra Faye replied to remya on 13-Jul-12 08:43 AM
Use case statement  in your select query as Satish suggested.
Rohan Dave replied to remya on 14-Jul-12 06:26 AM
You need to use "CASE WHEN" in your select query. CASE WHEN works similar to IF ELSE in SQL..

Select EmployeeID, EmployeeName, 
    CASE WHEN ISNUL(EmpGender,'') = 'M'
    THEN 'Male'
    ELSE   'Female'
    END
As [Full Gender]
From
employee