Monday, February 17, 2014

Populate varchar(max) or nvarchar(max) to SSIS string variable

How to import varchar(max) into SSIS string variable.

Database table

clip_image002

SSIS Varaibles
clip_image004

SSIS query result set object
clip_image006

The foreach loop has to have something in it otherwise the variables don’t get populated.

clip_image008

Execute SQL Task set up. There is only one record returned from the query. Make sure the the SQLStatement handles NULLs via ISNULL(xxx,'') or COALESCE(xxx,'')

clip_image010

clip_image012

Foreach loop setup.

clip_image014

clip_image016

2 comments:

  1. Declare @maxRowLength int = 50;
    with x as (
    select 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry''s standard dummy text ever since the 1500s. Over the years, sometimes by accident, sometimes on purpose (injected humour and the like).' data
    ),
    tmp(data,c,rn) as (
    select data,SUBSTRING(data, 1,@maxRowLength),@maxRowLength
    from x
    union all
    select data,SUBSTRING(data,rn,@maxRowLength),rn + @maxRowLength
    from tmp
    where rn < len(data)
    )
    select c,rn from tmp
    OPTION (MAXRECURSION 500);

    ReplyDelete
  2. you can split a large text to smaller chunks, in the rows and load them in foreach loop container,

    ReplyDelete