January 13, 2011 at 12:58 pm
Consider the following table:
CREATE TABLE source_data
(
source_ID int,
source_description varchar(8000)
)
I need to output data from this table to a text file with the following structure, where target_description cannot exceed 255 characters:
target_ID, target_sequence, target_description
If the value of source_ID is 1, and source_description exceeds 255 characters, I need to create multiple rows in the text file, with target_sequence being an incremented value for each new row. So if source_description contained 1020 characters, the result would be 4 rows, with target_ID being 1, and target_sequence being 1, 2, 3, and 4, and target_description being 255 character chunks from source_data.source_description.
So the question is: what is the most efficient way of doing this in SSIS? The source_data table could potentially have millions of rows.
Any help is appreciated!
TIA
January 13, 2011 at 1:08 pm
Do you have a Numbers/Tally table?
If so, this is pretty easy to do.
select *,
substring(LargeColumn, Number*255, 255) as SplitColumn
from dbo.MyTable
inner join dbo.Numbers
on Number <= len(LargeColumn)/255;
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 13, 2011 at 1:20 pm
I didn't, but I do now! So obvious when you see it. Thanks!
January 13, 2011 at 2:06 pm
Did you build it properly? You might want to check out the article The "Numbers" or "Tally" Table: What it is and how it replaces a loop. [/url]
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 14, 2011 at 2:45 pm
You can implement this requirement using data flow script, where based on the description column the input row is split into multiple rows according to the algorithm you have described. However if the GSquared solution works for you, it will be better and easier to maintain.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply