Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 SSIS Text File Import

Author  Topic 

Jayaseelan
Starting Member

6 Posts

Posted - 2008-10-18 : 23:39:52
Hi,
I am new to SSIS, can you please help me in the below mentioned example through SSIS.
1)I have a text file which contain two control numbers 1001 and 1002 with one column and two rows.
2) I need to take these two control numbers in a variable (ex varcontrol_numbers = 1001,1002)
3)Then i need to frame a dynamic procedure as shown below.
SELECT transaction,
amount
FROM trasactions
WHERE control_number IN (varcontrol_numbers)--from the variable

4)At last the output the procedure should be written to a new text file.

can you please help in performing the above mentioned steps in SSIS.

Thanking in advance.









visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-19 : 02:39:16
1.first add a data flow task to get the two row values from text file to a staging table
2.get the values from staging table to a recordset object variable using Execute SQL task.example below

query will be like
SELECT v.u
FROM
(
SELECT controlvalue + ','
FROM stagingtable
FOR XML PATH('')) AS v(u)

http://www.sqlservercentral.com/articles/SSIS/64014/

3. then use For Each loop and shred values and append to a variable
@User::varcontrol_numbers
http://blogs.conchango.com/jamiethomson/archive/2005/07/04/SSIS-Nugget_3A00_-Execute-SQL-Task-into-an-object-variable-_2D00_-Shred-it-with-a-Foreach-loop.aspx

4. finally use a execute sql task or command task to execute query using variable values

SELECT transaction,
amount
FROM transactions
WHERE ','+? +',' LIKE '%,'+cast(control_number as varchar(20))+',%'

then map parameter to control values variable @User::varcontrol_numbers
Go to Top of Page
   

- Advertisement -