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
 SQL Select Query

Author  Topic 

dhinasql
Posting Yak Master

195 Posts

Posted - 2008-06-07 : 08:27:35
Hi Friends,

I have a sql table, Named as tbl_Property, i have the column names are id,swimming,club,parking. [ Here swimming , club , parking are bit data type ]

The database will be filled with the following sample data

id Swimming Club Parking
1 0 1 1
2 1 1 1
3 0 0 0

Here i want to select property details by id, and which are the fields have 1 data, i want to select that column name.

Expected output for id=1 is

Club Parking

Expected output for id=2 is
Swimming Club Parking

Please help me how to do this?

Thanks in Advance


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-07 : 09:41:49
[code]SELECT CASE WHEN Swimming=1 THEN 'Swimming ' ELSE '' END +
CASE WHEN Club=1 THEN 'Club ' ELSE '' END +
CASE WHEN Parking=1 THEN 'Parking' ELSE '' END
FROM Table WHERE id=@ID[/code]
Go to Top of Page
   

- Advertisement -