I had done something cross databases before using sysdatabases, but this time I needed to search for specific text in any column on an table in a known database.
declare @command varchar(255)
declare @tablename sysname
declare @columnname sysname
declare @count int
DECLARE StatusCursor CURSOR FOR
select a.name,b.name from sysobjects a join syscolumns b on a.id = b.id where a.type ='U' order by a.name
Open StatusCursor
Fetch next from StatusCursor into @tablename, @columnname
WHILE @@FETCH_STATUS = 0
BEGIN
if(@columnname = 'FOO1')
begin
print @tablename
end
Fetch next from StatusCursor into @tablename, @columnname
END
CLOSE StatusCursor
Deallocate StatusCursor
No comments:
Post a Comment