Solved

SSIS SQL Server 2005 export to file

Posted on 2013-01-25
3
581 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
3 Comments
 
LVL 39

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Lessons learned during ten years of interviewing for SQL Server Integration Services (SSIS) and other Extract-Transform-Load (ETL) contract roles and two years of staff manager interviewing contractors.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now