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
 General SQL Server Forums
 New to SQL Server Programming
 Selecting Data based on a Boolean condition

Author  Topic 

NeilWhite
Starting Member

2 Posts

Posted - 2009-05-21 : 11:16:17
Hi There,
I am trying to produce a query based on an existing query to selectively omit data from a membership list.

My many query is :
SELECT Name,Address,Telephone FROM Members

but some members do not wish me to publisher their Telephone number, so I would like to produce another query to do that. I have added a boolean column in (called Permission) my table. In Visual Basic I would use the IIF command and would produce something like :

SELECT Name,Address,IIF(Permission=1,Telephone,"") FROM Members

but i don't know how to do this correctly in SQL. I would appriciate any help...

mavershang
Posting Yak Master

111 Posts

Posted - 2009-05-21 : 11:24:45
you could try

select case when permission=1 then Telephone else '' end
from members

quote:
Originally posted by NeilWhite

Hi There,
I am trying to produce a query based on an existing query to selectively omit data from a membership list.

My many query is :
SELECT Name,Address,Telephone FROM Members

but some members do not wish me to publisher their Telephone number, so I would like to produce another query to do that. I have added a boolean column in (called Permission) my table. In Visual Basic I would use the IIF command and would produce something like :

SELECT Name,Address,IIF(Permission=1,Telephone,"") FROM Members

but i don't know how to do this correctly in SQL. I would appriciate any help...

Go to Top of Page

NeilWhite
Starting Member

2 Posts

Posted - 2009-05-21 : 11:34:26
Thank you very much for the tip. With your help I have managed to achieve what I aimed to do. Thank you again.
Go to Top of Page
   

- Advertisement -