Thursday, September 30, 2010

How to export the data to existing EXCEL file from the SQL Server table


http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926
     
       
IF  EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0 AND srv.name = N'XLS')EXEC master.dbo.sp_dropserver @server=N'XLS', @droplogins='droplogins'
GO
    
EXEC sp_addlinkedserver N'XLS', 'Jet 4.0','Microsoft.Jet.OLEDB.4.0','c:\testing.xls',NULL,'Excel 5.0;

declare @text VARCHAR(400)

SET @text='HBS '

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 5.0;Database=c:\testing.xls;',  'SELECT * FROM [Sheet1$]') select EMP_NUMBER, emp_calling_name ,@text TEXT from DSI.hs_hr_employee --where  emp_number='000001'


No comments:

Post a Comment