|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 12:53 AM
Points: 1,130,
Visits: 1,276
|
|
Hi, I have table which have number of columns one of these columns contains value say 'ABC' I have to find the column name which contain ABC
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, May 03, 2013 3:06 AM
Points: 42,
Visits: 285
|
|
You can try the below however, this might take a long time depending on the number of records in the table.
USE YOUR_DATABASE_NAME GO DECLARE @MY_COL VARCHAR(50) DECLARE @QRY VARCHAR (255)
declare kursor cursor for SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'YOUR_TABLE_NAME' OPEN kursor FETCH NEXT FROM kursor INTO @MY_COL
WHILE @@FETCH_STATUS = 0 BEGIN
SET @QRY= 'SELECT '+@MY_COL+' FROM YOUR_TABLE_NAME WHERE '+@MY_COL+' =''ABC''' PRINT @QRY EXEC (@QRY) FETCH NEXT FROM kursor INTO @MY_COL END
CLOSE kursor DEALLOCATE kursor
|
|
|
|