Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 ** Export Results to Different Excel Sheets **

Author  Topic 

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-10-27 : 03:16:51
[code]Hi All,

I want to Export my results to different Excel Sheets.i.e : If I have two Select statements like the below

SELECT * FROM AdventureWorks.HumanResources.Department
SELECT * FROM AdventureWorks.HumanResources.Employee

the results of both queries should be exported to single Excel file with two different Sheets, one for Department another for Employee.

Currently i am using OPENROWSET to export the data
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test.xls;',
'SELECT * FROM [Sheet1$]')
SELECT * FROM AdventureWorks.HumanResources.Department

Thanks in advance[/code]

[code]"There is only one difference between a dream and an aim. A dream requires soundless sleep to see, whereas an aim requires sleepless efforts to achieve..!!"
[/code]

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-27 : 04:04:32
did you try specify two inserts using OPENROWSET with just only sheet names varying?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-29 : 06:53:16
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test.xls;',
'SELECT * FROM [Sheet1$]')
SELECT * FROM AdventureWorks.HumanResources.Department

INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\test.xls;',
'SELECT * FROM [Sheet2$]')
SELECT * FROM AdventureWorks.HumanResources.Employee

More informations are here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -