Tuesday, 20 August 2013

SQL 2008 Select certain columns have specific data

SQL 2008 Select certain columns have specific data

i have a table some of its fields are of a bit datatype. I need to select
only the [BIT] datatype columns and with the value of [TRUE]. i have the
following code to select only the [BIT] columns from a given table.
SELECT OBJECT_NAME(c.OBJECT_ID) TableName, c.name ColumnName
FROM sys.columns AS c
JOIN sys.types AS t ON c.user_type_id=t.user_type_id
join sys.all_objects as o on o.object_id = c.object_id
WHERE t.name = 'bit'
and o.name = 'TABLENAME' --this is the table name
ORDER BY c.OBJECT_ID
GO
Please tell me how to select only those with [TRUE] value
thanks

No comments:

Post a Comment