Solved

SSIS SQL Server 2005 export to file

Posted on 2013-01-25
3
592 Views
Last Modified: 2016-02-10
I need a good example link to:
Create a SSIS Package that:
retreives data through stored procedure
exports to excel file
names the file with mmddyyyy appended

IF filename_mmddyyyy already exists
create filename_mmddyyyy_1   2   3  etc
0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 500 total points
ID: 38820312
In SQL 2005 in particular you can do the export directly from a Stored Proc like in code below:


--SQL 2005 only
EXEC master..sp_makewebtask
      @outputfile = 'c:\testing.xls',
      @query = 'Select * from dbName.schemaName.tableName',
      @colheaders =1,
      @FixedFont=0,@lastupdated=0,@resultstitle='Testing details'




http://blog.sqlauthority.com/2008/01/08/sql-server-2005-export-data-from-sql-server-2005-to-microsoft-excel-datasheet/

USE [AdventureWorks];
GO
INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:\contact.xls;',
'SELECT * FROM [Sheet1$]')
SELECT TOP 5 FirstName, LastName
FROM Person.Contact
GO



--using BCP with column names:
bcp "select 'ProductID', 'Name', 'ProductNumber' union all select convert(varchar(10), ProductID), Name, ProductNumber from AdventureWorks2008R2.Production.Product" queryout "c:\temp\product.xls" -c -T
0
 
LVL 12

Expert Comment

by:Tony303
ID: 38829564
I use this in SSIS to derive a txt filename based on Year, Month, Day, Hour and Minute.  
Be aware, I am also using some previously derived variables..."Practice" and IndicatorNumber.
You could hardcode anything in those variables place....



@[User::Practice]  + "_Indicator" +  "_" + @[User::IndicatorNumber] + "_" + RIGHT( "0000" + (DT_STR, 4 , 1252) DATEPART( "year" , GETDATE() ) , 4 ) + RIGHT( "00" + (DT_STR, 2 , 1252) DATEPART( "month" , GETDATE() ) , 2 ) + RIGHT( "00" + (DT_STR, 2 , 1252) DATEPART( "day" , GETDATE() ) , 2 ) + "_" + RIGHT( "00" + (DT_STR, 2 , 1252) DATEPART( "hour" , GETDATE() ) , 2 ) + RIGHT( "00" + (DT_STR, 2 , 1252) DATEPART( "minute" , GETDATE() ) , 2 )  + ".txt"
0
 

Author Closing Comment

by:lrbrister
ID: 38831039
Perfect. Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question