Retrieve columns having a specific value

General
Fan

Retrieve columns having a specific value

Hi,

I have 100+ columns. I need to retreive columns having a specific value [Say 'ABC'] in any of the rows. 

Please help. 

Tags (2)
3 REPLIES
Teradata Employee

Re: Retrieve columns having a specific value

You can write the filter condition using a dynamic SQL like this:

select trim(columnname)||'=''ABC'' or '
from dbc.columns
where databasename='YourDabaBase'
and tablename ='YourTable'
and columntype in('CF', 'CV')
Teradata Employee

Re: Retrieve columns having a specific value

The columntype filter depends on data type, I was supposing the data type was char or varchar

Fan

Re: Retrieve columns having a specific value

Hi, I didn't mean column names but column value. 

Thanks.