using "AS" in a SQL statement

  • Hello All,

    I have the following query

    select fname, lname, '1' AS Status from tblname

    when I run this query as you all know it return fname and lname and plus an extra field with value of 1.

    Is there anyway that I can return 2 if fname = 'John', else keep the value 1?

    Thank you

  • You can use a CASE statement.

    The code will look something like this:

    SELECT fname, lname,

    CASE WHEN fname = 'John' THEN '2' ELSE '1' END AS Status

    FROM tbl

    Hope this helps.

    N. Williams

  • worked perfectly...

    Thanks a lot

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply