April 23, 2009 at 10:27 am
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.
April 23, 2009 at 10:33 am
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 (
April 23, 2009 at 10:35 am
how about
if exists (
select * from tableb )
begin
select columna, columnb, columnc from tableb
end
else
begin
select columna, columnb from tablea
end
David
April 23, 2009 at 10:49 am
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