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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get column name from value?

Author  Topic 

tskmjk
Starting Member

11 Posts

Posted - 2010-02-10 : 04:26:23
This is the strange request but I got this requirement from Operations department where the table structure is as follows:

Sno customername custno mobileno landlineno alterphno .....
----------------------------------------------------------

Customer through Inbound call provides a phone number which can be anything..so I would like to retrieve column name by this phone number for example..customer provides '1234576' as the phone number, I wouldnt know under which column this number resides, so I would like to know..Kindly help me on this...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-10 : 04:33:54
[code]
select column_name = 'mobileno'
from table
where mobileno = '1234567'

union all

select column_name = 'landlineno'
from table
where landlineno = '1234567'

union all

select column_name = 'alterphno'
from table
where alterphno = '1234567'

. . .
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 04:34:37
see

http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm

------------------------------------------------------------------------------------------------------
SQL Server MVP
Go to Top of Page

tskmjk
Starting Member

11 Posts

Posted - 2010-02-10 : 04:56:08
Thanks buddy
Go to Top of Page
   

- Advertisement -