Any Way to Change Case Statement Column Name Using Alias

  • Hi Folks

    trivial question on changing the column name using an alias in a CASE statment.

    Is there a way to do that in this example

    Would like to change "denylogin" to something else

    ===============

    select

    CAST (a.loginname as varchar(80)) as login_name,

    CASE denylogin

    WHEN '1' THEN 'Yes'

    WHEN '0' THEN 'No'

    ELSE

    'Unable to Decipher'

    END denylogin

    from

    sys.syslogins a

    order by

    a.loginname;

    go

    ===============

    Thanks

    Jim

  • JC-3113 (11/17/2009)


    Hi Folks

    trivial question on changing the column name using an alias in a CASE statment.

    Is there a way to do that in this example

    Would like to change "denylogin" to something else

    ===============

    select

    CAST (a.loginname as varchar(80)) as login_name,

    CASE denylogin

    WHEN '1' THEN 'Yes'

    WHEN '0' THEN 'No'

    ELSE

    'Unable to Decipher'

    END denylogin

    from

    sys.syslogins a

    order by

    a.loginname;

    go

    ===============

    Thanks

    Jim

    You should just be able to put 'END as SomeOtherName' on the line where you have 'END denylogin'.

  • Thanks Grasshopper

    that was it

    i was trying to add the alias to the line instead of replacing it

    Jim

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

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