SSIS Filename variable with wildcards - ssis

I am looking at creating a SSIS package that copies the latest file from a specific directory. There are multiple files output to the directory each day and each gets date and time stamped in the file name
FLATFILE_20150909_130801.txt
FLATFILE_20150909_230508.txt
I am only interested in the latest file during the day. Which will always have the same prefix 23 . I’ve written the expression as
"\\\\DESTINATION\\FLATFILE"+ "_"+ (DT_STR,4,1252)DATEPART( "yyyy" , getdate() ) + RIGHT("0" + (DT_STR,4,1252)DATEPART( "mm" , getdate() ), 2) + RIGHT("0" + (DT_STR,4,1252)DATEPART( "dd" , getdate() ), 2) + "_"+ "23"+ "****"+ ".sqb"
Which returns FLATFILE_20150909_23****.txt
Is there any way to assign wildcards to the characters in the string **** so it ignores these??

Related

How to pass text in configuration file with a call to parameter

I have a package that sends emails, I have it set with a configuration file so I can pass a parameter with the addresses, attachments, etc. that I want to use, one of these parameters is the Message_source:
in which I pass the content of the email.
my problem comes in that I want to pass formatted text and a dynamic field (date).
how can I do this so I can send something like this:
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::Email_Content].Properties[Value]" ValueType="String">
<ConfiguredValue>here I want to pass a date, here is the date: #Date</ConfiguredValue>
</Configuration>
so I can generate something like this:
here I want to pass a date,
here is the date: 05-01-2023
I know that I can parse the date with:
RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "-" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
however adding this to the config file right away doesn't work.
If it's going to work, I think you're going to add in a few more levels of indirection.
What you want is to have an Expression as the content of a variable. It's happy to assign your string to the Value property but what is being sent is not the evaluated #Date but the literal characters # D A T E
<Configuration ConfiguredType="Property"
Path="\Package.Variables[User::Email_Content].Properties[Expression]" ValueType="String">
<ConfiguredValue>"I want to pass a date, here is the date: " + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2) + "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2) + "-" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE())</ConfiguredValue>
</Configuration>
The same rules will apply with string building and all that so if you want to have it look like "I want to pass a date, here is the date: #Date" then you need to build out a valid expression. I'd create a Variable named Test and plug away until I get the syntax correct and then slap that, carefully, into your XML/dtsconfig
"I want to pass a date, here is the date: "
+ RIGHT("0" + (DT_STR, 2, 1252) DATEPART("dd" , GETDATE()), 2)
+ "-" + RIGHT("0" + (DT_STR, 2, 1252) DATEPART("mm" , GETDATE()), 2)
+ "-" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE())
Finally, if that isn't working then ensure that #[User::Email_Content] has the EvaluateAsExpression property set to True

SSIS Foreach loop adding extra date and extension to one file name

When my package runs the Foreach loop container to rename 4 excel files it adds the date to each files and then adds an extra date and extension to the 1 file in the folder.
Example: Contracts_010120.xlsx_010120.xlsx.
REPLACE( #[User::Copy_Temp_M_To_J] ,"_TEMP.xlsx", "")
+ "_"+Right("0"+ (DT_WSTR ,2) DATEPART("mm",GetDate()),2)
+ RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2)
+ RIGHT("0" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) ,2)
+ ".xlsx"
It's just doing it to one file in the folder.

Appendheader needs to append string, variable and then string again

Hopefully this is an easy one for someone out there. I need to append a long command that has strings and variables in it.
this->AppendHeader("Content-Range", "bytes " + offset "-" + (offset + part_size - 1) "/" + file_size);
This is not acceptable in C++. How can I format the above so the Header looks like
Content-Range: bytes 0-19/40
(just a fyi - offset is 0, part_size is 20 and file_size is 40)

Using Expressions in SSIS Casting Issue

I'm using expressions in the Control Flow to choose different Data Flow Tasks based upon the name o file being parsed (basically loading data from Excel Source into OLE DB Destination).
I'm using the following Expression and its variants to get the desired result:
(DT_I4) (DT_WSTR, 2) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
(DT_BOOL) (DT_WSTR, 2) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
(DT_BOOL) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
I basically just want the DFT to be executed only if the expression is true. There are some casting errors coming.
The most promising result comes when I use this expression:
(DT_WSTR, 2) FINDSTRING( #[User::srcFilePath] , "DIVISION", 1)
Where the answer is basically '45' in string form so I cannot use any logical operators or compare them against any numbers ...
Any help would be much appreciated.
Why not just compare the FINDSTRING result against 0 (not found)?
FINDSTRING("DIVISION_ABC.xls", "DIVISION", 1 ) > 0
That would evaluate to True - just replace "DIVISION_ABC.xls" with #[User::srcFilePath]

SSIS Derived Column Transformation

I am trying to develop a package which takes a string (in the format 1.02.3.04 or 01.02.03.4 and lots of other permutations) and amends this based upon the following rules
if the second character is a "." then pad the first group with a 0
FINDSTRING([mycolname],".",1) returns the position of the first "." and for all values of 2 then apply this rule and amend the string eg if 1.2.3.4 will return 2 the string should be 01.2.3.4
if the second instance of "." is 5 FINDSTRING([mycolname],".",2) then add a 0 in after the third character eg 01.02.3.4
if the third instance of "." is 8 FINDSTRING([mycolname],".",3) then add 0 in after the 6th character
I am a little stuck with some of the logic !
anyone help ??
in SSIS 2012 can be achieved with a one-liner Derived Column:
RIGHT("00" + TOKEN("1.02.3.04",".",1),2) + "." + RIGHT("00" + TOKEN("1.02.3.04",".",2),2) + "." + RIGHT("00" + TOKEN("1.02.3.04",".",3),2) + "." + RIGHT("00" + TOKEN("1.02.3.04",".",4),2)