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)
 Column Filter

Author  Topic 

m_weltm
Starting Member

8 Posts

Posted - 2007-06-11 : 15:37:29
I am having a problem finding a solution for this:
--this is only an example not a real table

Declare @t table(
addressNum int,
addressStreet varchar(8),
unitNumber varchar(10),
city varchar(20),
state varchar(2),
zip int
)

Insert into @t values(12, 'Jackson', 'apt.3D', 'Chicago', 'IL', 60607)
Insert into @t values(115, 'Briar', 'apt. 5F', 'Chicago', 'IL', 60657)

For certain queries I would like to filter the columns selected based on some user preferences. I.E. if some user doesn't want to see city state or zip I can perform some filtering such that I get NULL for those columns. Ideally it would work something like this

SELECT *
FROM (
--some derived table which has been filtered
) FilteredTable
WHERE id=@id

Thanks

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-06-11 : 16:06:52
Sample output, please....

e4 d5 xd5 Nf6
Go to Top of Page

m_weltm
Starting Member

8 Posts

Posted - 2007-06-11 : 16:25:28
addressNum addressSreet unitNumber city state zip
-------------------------------------------------------------------
12 'Jackson' 'apt.3D' NULL NULL NULL
115 'Briar' 'apt.5F' NULL NULL NULL

or if another user doesn't want to see unitNumber the query would result in:

addressNum addressSreet unitNumber city state zip
-------------------------------------------------------------------
12 'Jackson' NULL 'Chicago' 'IL' 60607
115 'Briar' NULL 'Chicago' 'IL' 60657
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-06-11 : 17:11:45
This is really a presentation issue that should be handled on the client side.

e4 d5 xd5 Nf6
Go to Top of Page
   

- Advertisement -