Hi, I am create a sql query for using this query you can find particular records in how many table and how much?
In this you pass your column name and record 'name' = put your column name 'XMas' = put your record which you find
declare @tablename varchar(500) declare @colname varchar(500)
CREATE TABLE #t(tablen varchar(500),countrecord int)
DECLARE RuleList CURSOR FOR select tab.name,col.name from sys.all_columns col left outer join sys.tables tab on tab.object_id = col.object_id where col.name = 'name' and tab.name is not null OPEN RuleList FETCH NEXT FROM RuleList into @tablename,@colname WHILE (@@FETCH_STATUS = 0) begin declare @Sql nvarchar(2000) set @Sql = 'INSERT INTO #t select '''+ @tablename + ''' , count(*) from ' + @tablename + ' where ' + @colname + ' = ''XMas''' --print @Sql execute sp_ExecuteSql @SQL FETCH NEXT FROM RuleList into @tablename,@colname end select tablen, countrecord from #t where countrecord <> 0 drop table #t CLOSE RuleList DEALLOCATE RuleList
|
No responses found. Be the first to respond and make money from revenue sharing program.
|