Using an if statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chudson007@hotmail.com

    Using an if statement

    I have a column in a table... ColumnA
    ColumnA contains positive and negative numbers
    What I want to do is insert an expression that basically does the
    equivalent of the following excel formula..

    If(ColumnA>=0," Use","Ignore")

    What should I change the following syntax to?

    SELECT *, ColumnA AS Expr1
    FROM Table

    Regards,
    CiarĂ¡n

  • David Portas

    #2
    Re: Using an if statement

    SELECT *,
    CASE WHEN columnA>=0 THEN 'Use' ELSE 'Ignore' END AS expr1
    FROM Table

    --
    David Portas
    SQL Server MVP
    --

    Comment

    • Simon Hayes

      #3
      Re: Using an if statement

      You're probably looking for CASE (see Books Online):

      select case when ColumnA >= 0 then 'Use' else 'Ignore' end as 'Expr1'
      from dbo.MyTable

      Simon

      Comment

      Working...