C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Export data from SQL Server to Excel without using SSIS or DTS


Posted Date: 15 Apr 2007    Resource Type: Code Snippets    Category: SQL

Posted By: Vadivel Mohanakrishnan       Member Level: Diamond
Rating:     Points: 10



Normally for exporting data from SQL Server to Excel one would use DTS (SQL 2k) or SSIS (SQL Server 2005). For some reason if at all you want to do it via query read on:

Step 1: Execute the code snippet



Exec sp_configure 'show advanced options', 1;
Go
Reconfigure;
Go

Exec sp_configure 'Ad Hoc Distributed Queries', 1;
Go
Reconfigure;
Go



Step 2: Create the excel file and then add the headings in the .xls file. [Important] The heading should be the same as that of the table columns.



Insert into Openrowset ('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:\VadivelTesting.xls;' ,
'Select * from [ProductInfo$]')
Select ProductID, ProductName
from dbo.tblProducts



Points which might interest you:

1. As long as the file is within your C: drive this sample would work. If at all your database is in a different machine from that .xls file you need to change Database=c:\VadivelTesting.xls; to UNC path. For example, Database=\\Servername\shareName (And need to provide appropriate permission).

2. Instead of "ProductInfo" replace it with your excel worksheet name.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Set first day of the week
Previous Resource: Compatibility level of database
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use