Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
declare @mycolumn varchar(20),
@mytable varchar(20),
@sql nvarchar(1000)
[COLOR=green]--create a cursor containing column and table names you want[/color]
declare coltab cursor for Select column_name, table_name
from INFORMATION_SCHEMA.COLUMNS
where column_name like 'z%' or
column_name = 'grant'
open coltab
[COLOR=green]--throw first row into variables[/color]
fetch next from coltab into @mycolumn, @mytable
[COLOR=green]--here, I build a temp table to hold the data we pull[/color]
create table #temp (oldCol nvarchar(20), data nvarchar(20))
[COLOR=green]--create a sql string using these variables in place of column names and table names[/color]
set @sql = 'insert into #temp (oldCol, data) (select ''' + @mytable + '_' + @mycolumn + ''', ' + @mycolumn + ' from ' + @mytable + ')'
[COLOR=green]--execute the sql command[/color]
exec sp_executesql @sql
[COLOR=green]--pull the next row in the cursor[/color]
fetch next from coltab into @mycolumn, @mytable
[COLOR=green]--start a loop to get through the entire cursor[/color]
while @@FETCH_STATUS = 0
BEGIN
set @sql = 'insert into #temp (oldCol, data) (select ''' + @mytable + '_' + @mycolumn + ''', ' + @mycolumn + ' from ' + @mytable + ')'
exec sp_executesql @sql
fetch next from coltab into @mycolumn, @mytable
END
[COLOR=green]--close and destroy the cursor[/color]
close coltab
deallocate coltab
[COLOR=green]--now get the data from the temp table and drop it[/color]
select * from #temp
drop table #temp
declare coltab cursor for Select column_name, table_name
from INFORMATION_SCHEMA.COLUMNS
where column_name like 'z%' or
column_name = 'grant'
set @sql = 'insert into #temp (oldCol, data) (select ''' + @mytable + '_' + @mycolumn + ''', ' + @mycolumn + ' from ' + @mytable + ' where '+ @mycolumn + ' = ''grant'')'