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.
Author |
Topic |
jscot
Posting Yak Master
106 Posts |
Posted - 2011-05-18 : 00:03:51
|
Hi guys,Here is the situation; I have source data like thisP#123245678 894 258 623523 513Here is my target tableP# Sub P#123 NULL245 NULL678 NULL894 678258 678623 678523 NULL513 523Note:- P# is a Parent, and Sub P# is a Child,Please help me out how I can done in SSIS or T-SQL, my whole project I am doing through SSIS. Any help would be big help for me. Thanks. |
|
latch
Yak Posting Veteran
62 Posts |
Posted - 2011-05-18 : 16:12:55
|
Hi,Take a script component in a Data flow task of the SSIS package;Thinking that the data comes from a .txt file:Consider script component as "SOURCE" and here is the code for CreateNewOutputRows: public override void CreateNewOutputRows() { string line; System.IO.StreamReader file = new System.IO.StreamReader("D:\\Desktop\\abc.txt"); while ((line = file.ReadLine()) != null) { string input = line; string[] A; A = input.Split(' '); for (int j = 0; j < A.Length; j++) { if (j == 0) { Output0Buffer.AddRow(); Output0Buffer.P = A[j]; Output0Buffer.SUB = "NULL"; } else { Output0Buffer.AddRow(); Output0Buffer.P = A[j]; Output0Buffer.SUB = A[j-1]; } Output0Buffer.EndOfRowset(); } } file.Close();}}Then store to your file Thats it.Thanks |
|
|
|
|
|