Solved

DTS Export Multiple CSV file (HELP)

Posted on 2004-08-18
13
946 Views
Last Modified: 2012-06-27
ok i know how to use DTS to export one sql query into a csv file
but the problem now is

i need to select multiple record out &export it all to diff csv file
i cant keep create alot of DTS object to extract diff diff file
cuz it would be alot n dynamic

for example
select * from student where class="6M"

i need to
select all student from diff class
and save into diff csv file

i did some reserach
and come through BCP
and stored procedure to export to csv
but yet not really understand it much

anyone can help on this
what the best implmentation
if possible show some sample code

thanks alot

0
Comment
Question by:bensonlaw
  • 4
  • 3
  • 2
  • +1
13 Comments
 
LVL 3

Expert Comment

by:alexpreston
ID: 11828267
You can set up 2 connections in DTS for this. The first will be your database, the second a destination text file (which you should create first). Then you can use a transform data task to copy the data you require into the text file.
0
 
LVL 3

Expert Comment

by:alexpreston
ID: 11828287
Let me re-state that in a clearer way.
Create your csv file (e.g. diff.csv).
In your DTS package, create a connection to your database, and a connection to the csv file (using data source "Text File (Destination)").
Then select both connections and create a new "Transform Data Task" between them.
0
 

Author Comment

by:bensonlaw
ID: 11828324
this method i know

let say i wan do a multiple query
select student from class a
select student from class b
and the list goes on

i wan to run a loop  in it
so i can export the query into diff diff csv file
so the file will be
classa.csv
classb.csv
classc.csv



0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 3

Expert Comment

by:alexpreston
ID: 11828362
Ah I see, sorry. That's more tricky, I'll give it some thought!
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 11828938
u can create more connections between the database and different csv files in the same DTS package ...
0
 

Author Comment

by:bensonlaw
ID: 11828993
ya i know
but the class is like 50 class
u wont wan create 50 connection to grab all
and the class is dynamic
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 11829019
create one connection to database and another to one of ur csv file .. then create a "activex script task" which will destination connection based on ur requirement ...
0
 
LVL 10

Accepted Solution

by:
Jay Toops earned 50 total points
ID: 11829925
LOL..

Not even close guys..

This is what you will need to do ...
you will want to repetitively invoke your csv export step with an active-x Task
effectively taking over flow control from dts
the active-x script task will be first followed by a SETUP loop step
the export to csv step
then the Flow control Step active-x Script
which will reset the status of the Export step and
increment the loop counter.

You probably should setup a query from and load it into a global variable
with an output parameter in a SQL task step. (ALSO a pain to do)
and do the Next record logic in the Flow control active-x script

and you will have to dynamically configure the csv export step for each
execution as well
You will have to get the name of the task by going into disconnected edit from the main menu and looking through the steps although the name will be DTSTask_DTSDataPumpTask_1 Unless you have created other data pump tasks in this
package.

Like so

function main()
set pkg=dtsglobalvariables.parent
pkg.steps("DTSTask_DTSDataPumpTask_1").executionstatus=DTSSTEPExecStat_Waiting
pkg.steps("DTSTask_DTSDataPumpTask_1").DestinationObjectName="c:\thenewname.csv"
pkg.steps("DTSTask_DTSDataPumpTask_1").SourceSQLStatement="select * from sysusers where [name]='fred' "

end function
0
 
LVL 3

Expert Comment

by:alexpreston
ID: 11829971
I told you it was more tricky ;)
0
 
LVL 10

Expert Comment

by:Jay Toops
ID: 11830321
That is an Understatement... LOL ...
Took me a goood long time to figure out how to do this ..

I replaced a DTS package that had 50 steps with one that had 10
and i didn't have to update it every time someone added ANNOTHER
file to process .. JUST loop ..   and i put all my steps into config table(s) ..

but thats ANNOTHER story ..


Jay

0
 
LVL 10

Expert Comment

by:Jay Toops
ID: 12142748
Thank Darth
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query 2 31
Index and Stats Management-Specific tables 8 21
SQL 2012 clustering 9 11
MS SQL Delete Duplicate Rows Only 2 15
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

809 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