SourceCode/PROMS/SQL/AllDatabaseFindIndentTHEN.sql

14 lines
969 B
Transact-SQL

declare @CommandLine nvarchar(max)
SET @CommandLine = 'select ''{Name}'' dbname, count(*) howmany, ' + --cc.contentid, type, text,
'case when gg.contentid is null then ''not grid'' else ''grid'' end isgrid' +
' from {Name}.dbo.contents cc left join {Name}.dbo.grids gg on gg.contentid = cc.contentid' +
' where text like ''%'' +nchar(5) + ''% THEN %'' COLLATE Latin1_General_CS_AS ' +
'group by case when gg.contentid is null then ''not grid'' else ''grid'' end'
declare @CommandLines nvarchar(max)
select @CommandLines = Coalesce(@CommandLines + ' UNION' + char(10), '') + Replace(@CommandLine,'{Name}',Name)
from Sys.Databases where name like 'VEPROMS%'
Set @CommandLines = 'Select * from ( ' +@CommandLines + ') t1 where HowMany > 0'
print @CommandLines
EXEC SP_EXECUTESQL @CommandLines
select contentid, substring(text, charindex('THEN', text)-5, 15) found from veproms_BGE_STP.dbo.contents where text like '%' + nchar(5) + '% THEN %' COLLATE Latin1_General_CS_AS