Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SET NOCOUNT ON
- DECLARE @ItemName varchar(500)='badcaseitem'
- select
- 'IF EXISTS (SELECT TOP 1 1 FROM ' + col.TABLE_NAME + ' WHERE ' + col.COLUMN_NAME + ' = ''' + @ItemName + ''') PRINT ''SELECT ' + col.COLUMN_NAME + ' FROM ' + col.TABLE_NAME + ' WHERE ' + col.COLUMN_NAME + ' = ''''' + @ItemName + ''''' '';'
- from INFORMATION_SCHEMA.COLUMNS col
- JOIN information_schema.tables tbl
- ON tbl.table_name = col.table_name
- AND tbl.table_schema = col.table_schema
- AND tbl.table_catalog = col.table_catalog
- AND tbl.table_type <> 'VIEW'
- where DOMAIN_NAME = 'ItemType'
- ORDER BY col.TABLE_NAME
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement