Do not show column in a Case When statement

  • Hi All,

    I have a need not to show a column in a query result in a certain case. Here is my query:

    SELECT ColumnA, ColumnB,

    CASE WHEN (SELECT COUNT(*) FROM TableB) <> 0 THEN

    ColumnC END) AS ColumnA

    FROM TableA

    IF the count is zero then ColumnC should not be displayed, but ColumnA and ColumnB should display.

    Thanks.

  • ramadesai108 (4/23/2009)


    Hi All,

    I have a need not to show a column in a query result in a certain case. Here is my query:

    SELECT ColumnA, ColumnB,

    CASE WHEN (SELECT COUNT(*) FROM TableB) 0 THEN

    ColumnC END) AS ColumnA

    FROM TableA

    IF the count is zero then ColumnC should not be displayed, but ColumnA and ColumnB should display.

    Thanks.

    How about

    if exists (

  • how about

    if exists (

    select * from tableb )

    begin

    select columna, columnb, columnc from tableb

    end

    else

    begin

    select columna, columnb from tablea

    end

    David

  • That worked, thanks.

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

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