Create Folders Dynamically by looping in a database table
Hi all, I am new to SSIS, and would like to seek help in doing some requirements. I need to create Folders based on the records of a certain table. For example, my table contains the records below: MyTable UserName Quota UserN1 100 UserN2 150 UserN1 120 UserN2 110 UserN1 112 UserN3 155 I need to create folders based on the UserName field, i.e. I need SSIS to dynamically create the folders UserN1, UserN2, UserN3. Can anyone show me the steps to do this? Thank you in advance.
January 21st, 2011 2:01am

Take an execute sql task and capture all the UserNames in an object variable. After that use a for each loop container to iterate through all the values stored in object variable and save the individual names in a string varibale. Inside for each loop take a script task and create the folders. Execute SQL Task : General---ResultSet as Full Result Set and write the sql statement as Select UserName from the tablename. Then go to Result Set in left pane and give result name as 0 with varibale name as an object variable. For each loop: Inside Collection tab, you need to select foreachADOenumerator and select the object variable. Click on the variable mappings and set the index as 0 with variable as the string variable. Scrip task: Select the string variable as the read only varibale and write the script as: Imports System Imports System.Data Imports System.Math Imports Microsoft.SqlServer.Dts.Runtime Imports System.IO Public Sub Main() Dim directory As Directory Dim file As File Dim filepath As String filepath = "D:\BISamples\" + Dts.Variables("User").Value.ToString() 'file.Create(filepath) directory.CreateDirectory(filepath) Dts.TaskResult = ScriptResults.Success End Sub Note: User is the string variable I have used in the sample package. Nitesh Rai- Please mark the post as answered if it answers your question
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 2:26am

Thanks so much for the reply Nitesh! I'll try this one.
January 21st, 2011 2:28am

1) Use the query in a Execute SQL Task and store the result in a variable. 2) Use a Foreach Loop Container to loop through your dataset that is stored in the variable 3) Use a File System Task within the loop to create the folder
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2011 2:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics