CREATE TABLE Test ( EDate Datetime, Code varchar(255), Cdate int, Price int ); drop table Test insert into Test values('2015-06-19','LOP',20150701,12) insert into Test values('2015-06-22','LOP',20150701,26) insert into Test values('2015-06-23','LOP',20150701,69) insert into Test values('2015-06-23','LOP',20150701,77) insert into Test values('2015-06-23','LOC',20150701,73) insert into Test values('2011-04-08','LOP',20110501,97) insert into Test values('2011-04-07','LOP',20110501,11) insert into Test values('2011-04-06','LOP',20110501,61) insert into Test values('2011-04-08','OBP',20110501,37) insert into Test values('2011-04-08','OBC',20110501,105) insert into Test values('2011-04-07','OBP',20110501,19) insert into Test values('2011-04-06','OBP',20110501,25) insert into Test values('2015-06-19','RXP',20150701,92) insert into Test values('2015-06-22','RXP',20150701,43) insert into Test values('2015-06-24','RXP',20150701,22) insert into Test values('2015-06-24','RXP',20150701,28) insert into Test values('2015-06-24','RXC',20150701,43) insert into Test values('2015-06-24','OHP',20150701,43) insert into Test values('2015-06-23','ONP',20150701,43)
I have this Query and the below output:
EDate Code CDate Price
2015-06-24 RX 20150701 22
2015-06-24 RX 20150701 28
2015-06-24 RX 20150701 43
2015-06-23 NG 20150701 43
2015-06-24 HO 20150701 43
2011-04-08 RB 20110501 37
2011-04-08 RB 20110501 105
2015-06-23 CL 20150701 69
2015-06-23 CL 20150701 77
2015-06-23 CL 20150701 73
SELECT EDate, case when Code in ('LOP','LOC') then 'CL' when Code in ('OBP','OBC') then 'RB' when Code in ('RXP','RXC') then 'RX' when Code in ('OHP','OHC') then 'HO' when Code in ('ONP','ONC') then 'NG' Else 'CodeNotPresent' end Code,CDate,Price FROM Test t WHERE EDate = (SELECT MAX(EDate) FROM Test WHERE code = t.code)
Now the task is to create SSIS package which will create different .txt file for each Code
1) RX20150624.txt
2015-06-24 00:00:00.000 RX 20150701 22
2015-06-24 00:00:00.000 RX 20150701 28
2015-06-24 00:00:00.000 RX 20150701 43
2) NG20150623.txt
2015-06-23 00:00:00.000 NG 20150701 43
3) HO20150624.txt
2015-06-24 00:00:00.000 HO 20150701 43
And so on..
But the requirement is to have a dynamic query where we can have more number of Codes or less number of codes and similarly the package should generate dynamic text files, one .txt file per code.
What is the best way to create a package which can meet the above requirement?