October 25, 2007 at 1:24 am
Hi,
I want to make a query which can query a table and find out records with a specific value in any column.
For ex:
I have a table emp with 20 columns.
I want to get all records which has -3 in any of the columns and the columnname for that column.
Thanks
Pankaj
October 25, 2007 at 2:56 am
I'm afraid you will need to create the condition expression using OR and list all the relevant columns. On the other hand you do not need to write this condition yourself, you can generate a skeleton by a simple statement
DECLARE @a VARCHAR(1000)
SET @a = ''
SELECT @a = @a + name + '=-3 OR '
FROM sys.columns
WHERE object_id = OBJECT_ID('sometable')
AND system_type_id = 56
SELECT STUFF(@a, LEN(@a) - 2, 3, '')
Regards,
Andras
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply