i have below stuff an i write each result in excel sheet . i have an issue to write in excel sheet of each sql result
drop table #table_Northwind
create table #table_Northwind
(
RowID int not null identity(1,1) primary key,
column_name varchar(50)
)
insert into #table_Northwind (column_name)
(SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
where TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG='Northwind' )
--select * from #table_Northwind
declare @tbl_name nvarchar(50)
declare @i int
select @i = min(RowID) from #table_Northwind
declare @max int
select @max = max(RowID) from #table_Northwind
while @i <= @max begin
SELECT (select column_name from #table_Northwind where RowID=@i) 'TableName' , o.name, [Scehma]=schema_name(o.schema_id), o.type
FROM sys.sql_modules m
INNER JOIN sys.objects o
ON o.object_id = m.object_id
WHERE m.definition like +'%'+ (select column_name from #table_Northwind where RowID=@i) +'%'
set @i = @i + 1
end