SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Column Name


Column Name

Author
Message
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5136 Visits: 2767
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

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
arunyadav007
arunyadav007
SSC-Enthusiastic
SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)SSC-Enthusiastic (150 reputation)

Group: General Forum Members
Points: 150 Visits: 299
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search