case when use

  • hi,

    This is my Data.

    ID---FirstName---LastName-------------CreatedON

    8-----A------------C---------------2014-09-15 02:03:02.000

    8-----A------------C---------------2014-09-15 02:41:18.000

    5-----S------------D---------------2014-09-15 03:37:35.000

    1-----S------------D---------------2014-09-15 09:19:30.000

    0-----S------------D---------------2014-09-15 02:27:12.000

    D-----I------------U---------------2014-09-15 03:03:16.000

    i want when ID 8 Show First name last name and Created On Data related to ID 8 Display none.

    please help me out.

    thanks for the help

    immad

  • immaduddinahmed (9/23/2014)


    hi,

    This is my Data.

    ID---FirstName---LastName-------------CreatedON

    8-----A------------C---------------2014-09-15 02:03:02.000

    8-----A------------C---------------2014-09-15 02:41:18.000

    5-----S------------D---------------2014-09-15 03:37:35.000

    1-----S------------D---------------2014-09-15 09:19:30.000

    0-----S------------D---------------2014-09-15 02:27:12.000

    D-----I------------U---------------2014-09-15 03:03:16.000

    i want when ID 8 Show First name last name and Created On Data related to ID 8 Display none.

    please help me out.

    thanks for the help

    If you don't want to display the rows where ID <> 8, you can use a WHERE clause to not return those rows.

    SELECT FirstName, LastName, CreatedOn

    FROM table_name

    WHERE ID = 8;

    If you want to display the row with nothing in it (but why?), you can use a CASE statement.

    SELECT CASE ID WHEN 8 THEN FirstName ELSE NULL End FirstName,

    CASE ID WHEN 8 THEN LastName ELSE NULL END LastName,

    CASE ID WHEN 8 THEN CreatedOn ELSE NULL END CreatedOn

    FROM table_name;

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

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