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 2008 Forums
 SSIS and Import/Export (2008)
 SSIS QUESTION

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 this

P#

123

245

678 894 258 623

523 513

Here is my target table

P# Sub P#

123 NULL

245 NULL

678 NULL

894 678

258 678

623 678

523 NULL

513 523

Note:- 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




Go to Top of Page
   

- Advertisement -