I have a table which has two columns - city and country. Given a string 'X', how to know the column name which has the value 'X'?
For example, if 'X' is new york, query should return column name City and if 'X' is USA, query should return column name Country.
SELECT CASE WHEN city = 'X' THEN 'City' ELSE 'Country' END column_Value FROM [table_Name] WHERE city = 'X' OR country = 'X';
You can make use of the above query.