Advertisement
bluebunny72

Item rename

Apr 13th, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.62 KB | None | 0 0
  1. SET NOCOUNT ON
  2. DECLARE @ItemName varchar(500)='badcaseitem'
  3. select
  4.        '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 + ''''' '';'
  5. from INFORMATION_SCHEMA.COLUMNS col
  6. JOIN information_schema.tables tbl
  7.        ON tbl.table_name = col.table_name
  8.           AND tbl.table_schema = col.table_schema
  9.           AND tbl.table_catalog = col.table_catalog
  10.           AND tbl.table_type <> 'VIEW'
  11. where DOMAIN_NAME = 'ItemType'
  12. ORDER BY col.TABLE_NAME
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement