Quantcast
Viewing all articles
Browse latest Browse all 24688

Convert String DT_WSTR package level variable @User::FileNumber to Int (DT_I4)for arithmetic operations.

Problem:

Casting expression DT_WSTR to DT_I4 failed!

Bit of Background:

I have a string (DT_WSTR) user variable named @User::FileNumber at package level scope which in turn is used in a ForEach loop in Variable Mappings.This variable basically returns file number = 1,2,3,4….15. which I am using in a faltfile connection string variable to dynamically create the output file name: Test_Extract_File_1_20150731100000.txt

Here is the Flatfile Connection String assigned to the [GetDynamicFilename] variable:

@[User::Output_Path] + "\\Test_Extract_File_" +@[User::FileNumber]+"_"  + replace((DT_WSTR, 10) (DT_DBDATE) GETDATE(),"-","") + "100000" + ".txt"

What I would like to do is amend this connection string so that@User::FileNumber  is added to “100000” in the file name. i.e. new output file name format should be: Test_Extract_File_20150731100001.txtwhere we need file number returned via @User::FileNumber added with “100000” Eg: if @User::FileNumber =12 then “100000” + 12 = 100012 thus the new filename should beTest_Extract_File_20150731100012.txt.

Thought I could achieve this by creating another variable named:User::Derive_FileNumber of type int to perform the above addition and then update the flatfile connection string as follows:

@[User::Output_Path] + "\\Test_Extract_File_" + @[User::FileNumber] +"_" + replace((DT_WSTR, 10) (DT_DBDATE) GETDATE(),"-","") +(DT_WSTR, 10) @[User::Derive_FileName]  + ".txt"

But User::Derive_FileNumber of type int is not doing what I need!

Here is the expression for this variable where I want “100000” added with file number User::Derive_FileNumber

(DT_I4) "100000" +  @[User::FileNumber]  -- understandably fails because differing datatypes

Also tried variation of this by explicit casting but no good!

(DT_I4) "100000" + (DT_I4)  (ISNULL(  @[User::FileNumber]) ? "0" : @[User::FileNumber])

 it’s giving me casting error saying: Cast expression DT_WTSR to datatype DT_I4 failed.

Help, thanks.




Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>