Experts Exchange connects you with the people and services you need so you can get back to work.
DECLARE @tablename AS SYSNAME = 'IMC';
DECLARE @sqlCondition AS VARCHAR(MAX);
SELECT @sqlCondition = COALESCE(@sqlCondition + CHAR(13) + ' OR ', '') + '[' + COLUMN_NAME + '] LIKE ''SEARCH TERM%'''
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE c.TABLE_NAME = @tablename
AND c.DATA_TYPE IN ('VARCHAR', 'NVARCHAR')
PRINT('SELECT * FROM ' + @tablename + CHAR(13) + 'WHERE ' + @sqlCondition + CHAR(13) + ';');
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.