Script task programming

  • Hello!

    I would like to change a variable via Script task in my SSIS package.

    The variable is a string type date (Dátum). the value of the variable must be 8 days earlier day in this format: 100120 (2010.01.20 if today is 2010.01.28)

    My script is looking this:

    Public Sub Main()

    '

    Dts.Variables("Dátum").Value = Right("0" & Year(Now() - 8), 2) & Right("0" & Month(Now() - 8), 2) & Right("0" & Day(Now() - 8), 2)

    '

    Dts.TaskResult = Dts.Results.Success

    End Sub

    My problem is that the Now() - 8 is error.

    I can't find any reference for the Visual Basic.NET Thats why I ask you to help my little problem.

    Please help me! Thanks

  • Try this:

    Public Sub Main()

    Dts.Variables("Datum").Value = Right("0" & DateAdd(DateInterval.Day, -8, Today).Year, 2) & Right("0" & DateAdd(DateInterval.Day, -8, Today).Month, 2) & Right("0" & DateAdd(DateInterval.Day, -8, Today).Day, 2)

    Dts.TaskResult = ScriptResults.Success

    End Subb

    Regards,

    Willem
    http://wschampheleer.wordpress.com[/url]

  • Hello!

    Thank you very much for the fast help!

    It is working correctly.

    Do you have a link where I can find some language reference for VB.NET?

  • You're welcome.

    Can't help you with the link - I'm not a programmer myself :-).

    Actually, you do not really need a script task to solve your problem: you can use an Execute SQL Task and do the transformation in T-SQL like this:

    SELECT CONVERT(CHAR(6),DATEADD(d,-8,GETDATE()),12)

    Set the ResultSet to single row and map the output to your parameter.

    Saves you the trouble of learning VB or C# 😀

    Regards,

    Willem
    http://wschampheleer.wordpress.com[/url]

  • Thanks

  • You could have a look here and see where the links take you.


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

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