question on IIF Expression

  • Based on variable value how to  write an IIF condition

    IF IsActive = 0 do the following to create test1 file

    @[User::Path]+ "\\" + "Test1_"+(DT_WSTR,4)YEAR(GETDATE()) + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2)+ RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2)+".txt"

    else create test2 file

    @[User::Path]+ "\\" + "Test2_"+(DT_WSTR,4)YEAR(GETDATE()) + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2)+ RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2)+".txt"

     

  • Using a Conditional Expression. Syntax here.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I tried this way

    @[User::IsActive] == "0" ? "@[User::Path]+ "\\" + "Test_"+(DT_WSTR,4)YEAR(GETDATE()) + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2)+ RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2)+".txt"" ? "@[User::Path]+ "\\" + "Test_"+(DT_WSTR,4)YEAR(GETDATE()) + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2)+ RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2)+".txt""

     

    Its given error like the token "\" at line number "1", charcter number 56 was not recognized. expression cannot be parsed

  • Something like this?

    @[User::Path] + "\\" + (@[User::IsActive] == "0" ? "Test1_" : "Test2_") + (DT_WSTR,4)YEAR(GETDATE()) + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2)+ RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2)+".txt"

    This would probably be much simpler to accomplish in a script task - with C# code to generate the file name.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Jeffrey Williams wrote:

    Something like this?

    @[User::Path] + "\\" + (@[User::IsActive] == "0" ? "Test1_" : "Test2_") + (DT_WSTR,4)YEAR(GETDATE()) + RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2) + RIGHT("0" + (DT_WSTR,2)DAY( GETDATE()), 2)+ RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2)+".txt"

    This would probably be much simpler to accomplish in a script task - with C# code to generate the file name.

     

    Yep. Or dump the date portion of this expression into a separate variable and simply reference that variable in the above.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 5 posts - 1 through 4 (of 4 total)

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