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

I'm going to ignore your poorly formatted code.
But when I want files that Excel can use I write .CSV files so I don't have to worry which Excel version will use this file.
A simple Google with "how to write a csv file from _____" finds more ideas and code examples. Here you omitted what language was going to be used.

commented: Given the mention of the Northwind demo, I am assuming that it is MS Access. +14

I second writing to a csv file and this usually works. Recently I was having an issue with this very thing, where the result had cells with commas. No amount of trying to force various breaks between data cells would allow me to import into a spreadsheet without those commas being seen as separaters. Out of deperation I tried saving the csv as a .xls file and that worked. All of the commas within the various data cells where no longer an issue. The spreadsheet app (OpenOffice in this case) still opened the file as a normal csv import but the commas were no longer a problem. I use OpenOffice on a Mac, incase it's a platform related issue. Something to consider.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.