Home

MS SQL: If Statment within Select

Posted by SteveHardie | On: Jun 17 2010

When creating a SELECT query, sometimes you may want to display a dynamic field with a different value depending on a certain condition. Below is an example of how to use an IF Statment for creating a column within a select query:

SELECT Field1, Field2, PriceField
    case when PriceField > 200
            then 'Expensive' 
            else 'Value' end as PriceType
  FROM TableName

Leave a comment