SSIS Using Variables

  • I have a scenario where I am struck.....I get Data in the form of Text Files and I have to dump them in SQL Sever using SSIS. Now In the SSIS Package I am doing various data validations according to teh business requirement. BUt the problem is during the data validation teh rows which do not satisfy the rules need to be redirected into another text file and Now I have to check How much percentage of the whole file has error row(the rows whch does not satisfy the data validation rules and if they exceed 50% of teh whole file then that file is rejected other wise it is accepted. To implement this I started with a variables, I took three variabes InputErrorRows, OutputErrorRows and TotalErrorRows

    InputRows Variable contains Total No of Input Rows

    OutputRows Variable contains the Final No of Output Rows after the data vadation Amount

    TotalError Rows should be InputRows - OutputRows and Using this TotalErrorRows Variable I need status the Input file as Accepted or Rejected. But I am not abe to move further from decalring thsi variables I have no clue how to implement them to get the required output. Please help me out IF any one has any other way to do this it would be gr8. Thanks In Advance

  • Hi,

    Not too clear on your question, but heres a possible solution.

    1.Import text file to SQL

    2.Create 3 variables, TotalRows, ValidatRows, InvalidRows

    declare @ValidRows float

    declare @InvalidRows float

    Declare @TotalRows float

    3. Assign values to variables to calculate error percentage

    set @ValidRows = (select count(*) from table where rows are valid)

    set @TotalRows = (select Count(*) from table)

    set @InvalidRows = (@TotalRows-@ValidRows)/@TotalRows

    4.Insert data only if error is less than 50%

    if @InvalidRows <= 0.5

    print 'error at '+ cast(@InvalidRows*100 as char(5)) +'% '+'Statement to insert data here'

    else

    print 'error at '+ cast(@InvalidRows*100 as char(5)) +'% '+'No data inserted'

    replace print with your insert statements.

    hope this helps

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply