Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need Help With Conditional Exclusion of Columns

Author  Topic 

bigsapper
Starting Member

8 Posts

Posted - 2009-05-01 : 09:30:19
I have a query that I would like to completely exclude certain columns from the select clause if a flag is not set. Something similiar to ...

SELECT a, b, c,
IF @IsAdmin = 1
BEGIN
d, e, f
END
FROM mytable


Obviously, the previous doesn't compile. Is there a way to do this in a single statement?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-01 : 09:53:13
this is not possible except using dynamic SQL


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -