SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSIS Exporting to Multiple Excel Files


SSIS Exporting to Multiple Excel Files

Author
Message
ByronOne
ByronOne
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4006 Visits: 583
Hi everyone

I have to send invoices to our customers each month which is a time consuming manual process ;(

The invoices are created by running the following SQL
SELECT
CustomerID,
CustomerName,
ProductID,
ProductName,
Store,
State,
SalePrice
FROM dbo.SALES
WHERE CustomerID = '1234'
Currently, I have to painstakingly run the script for each customer, paste the output from SSMS into Excel and save the file as [Customer name].Monthly Invoice [Month Name and Year].xls
I know there must be an SSIS solution but really need help in trying to put this together - any pointers, articles, script would be greatly appreciated.
BO
sgmunson
sgmunson
SSC Guru
SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)SSC Guru (89K reputation)

Group: General Forum Members
Points: 89903 Visits: 6925
Take a look at the For Each Loop container. You'll need to set up a number of package variables to handle things like the varying names of the spreadsheets, and you can probably create a stored procedure to handle the query for each customer based on the customer id value. You can generate those as the query that sustains the For Each Loop container.

Steve
‌(aka sgmunson)
Smile Smile Smile
Health & Nutrition
Jack Corbett
  Jack Corbett
SSC Guru
SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)

Group: General Forum Members
Points: 164994 Visits: 15133
Have you considered using SSRS and putting a page break based on customer id and save as a PDF or as Excel?



Jack Corbett
Consultant Straight Path Solutions
Dont let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a QuestionHow to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Ponnuru
Ponnuru
SSC-Enthusiastic
SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)SSC-Enthusiastic (161 reputation)

Group: General Forum Members
Points: 161 Visits: 420
Hi Byron,
You can do it by using For each loop container.Basically divide the whole work into two parts.First Generate the excelsheet and create sheet names using Execute SQL Task and insert the data into excel sheet using DataFlowTask.

1.First list out all customer names and save it to Object variable using ExcuteSQL Task.
2.Next step,add forreach loop container and select ForEachAdo Enumarator.
3.Go to -->Variable Mapping --> Map Customer name to one variable.
4.Take execute SQl task inside Foreach loop container. -
-> Choose connectionType --Excel
--> Connection -- create excelconnection manager and select that connection.
--> SQLSourceType -- Variable
-- > Create a variable and build expression like below
"CREATE TABLE `"+(DT_STR,20,1252) @[User::VariableName] +"` (
`Column1` NVARCHAR(255),
`Column2` NVARCHAR(255),
`Column3` NVARCHAR(255),
`Column4` NVARCHAR(255),
`Column5` NVARCHAR(255)
)"
This will create a excelsheet with customername as sheetname.

5.Create DataFlowTask and
--> Source query pass customer name in where clause
-- Target as excelsheet and sheet name UserName.

You can create excelsheet dynamically by building expression and passing that expression value to excelconnection manager.
ByronOne
ByronOne
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4006 Visits: 583
Thanks for the responses guys.

I have gone with your suggestion Ponnuru - thanks for setting it out in such detail.

BO
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search