Environment: SQL Server 2005/2008, pubs database
I inserted a dataset variable into the table as shown below using the information_schema tables.

Now I would like to update the flag column based on the result of the query in the dSQL column. I managed to update the use of loops / cursor, and then use sp_executeSQL to update the column and then update the flag column later. But is there an alternative dial-based method without a loop across all the individual lines?
use pubs go declare @dsql Nvarchar(max)='', @tablename varchar(100), @colname varchar(100) declare @t table ( TABLE_NAME varchar(100), COLUMN_NAME varchar(100) ) insert into @t select distinct t.TABLE_NAME, c.COLUMN_NAME from information_Schema.tables t inner join information_Schema.columns c on t.TABLE_CATALOG = c.TABLE_CATALOG where t.TABLE_SCHEMA = c.TABLE_SCHEMA and t.TABLE_TYPE = 'BASE TABLE' and c.DATA_TYPE = 'varchar' select *, Dsql = 'select ' + COLUMN_NAME + ' from ' + TABLE_NAME + ' WHERE ' + COLUMN_NAME + ' = ''Menlo Park''', '' as Flag FROM @t GO
I had the idea of ββcreating a function and calling a function for each line to execute a separate query statement, but calling a function for each record can be a performance hit.
Ram
source share