You might want to try something like declare @fields varchar(200) set @fields=''; select @fields=@fields+ CASE WHEN FieldName1 IS NULL THEN 'FieldName1,' END, @fields=@fields+ CASE WHEN FieldName2 IS NULL THEN 'FieldName2,' END from TableName select @fields as ColumnName
You can loop around this with a cursor and dynamically build the CASE statements. Joe ----- Original Message ----- From: "Patti G. L. Hall" <[EMAIL PROTECTED]> To: "CF-Talk" <[EMAIL PROTECTED]> Sent: Wednesday, September 18, 2002 10:54 AM Subject: SQL: Returning columns with null values when specific columns are unknown at runtime > Is there a way to write a MSSQL 2k query that will return a result set that > contains only columns with null values when you don't know explicitly which > columns those will be? > > So if I have this data > > pk | col 1 | col 2 | col 3 | col 4| > 1 1 2 null null > 2 null 4 null null > > I'd like a query that would return col 3 and col 4 where pk = 1 or col 1, > col 3 and col 4 where pk=2. > > Is this possible? > -Patti > > ______________________________________________________________________ Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists