Welcome to blogs.conchango.com Sign in | Join | Help

Welcome to blogs.conchango.com

SSIS Junkie

SSIS: Evaluating variables as expressions

I have aluded as to the use of SSIS property expressions quite a few times on this blog. Regular readers will know what I think of them by now - they're a great mechanism for dynamically modifying the behaviour of your SSIS package at runtime. In short, property expressions ROCK!

Something that I haven't mentioned before but that is very very similar is the ability to evaluate a variable as an expression. This is an alternative to just using your variables as a store of data at runtime - evaluating as an expression means that your variables can be dynamic in exactly the same way that task properties can be.

Recently a question was posed on a newsgroup that got me thinking about this some more. In short the poster was building an SSIS package to load a file. The filename contained a date in the form "MMDDYYYY.xls" and he wanted to have an SSIS variable to contain the name of the file to be loaded - that being a file containing today's date. He thought that package configurations were the key to solving this - not so!

The way to do this is to set 2 properties of the variable as follows:

  • EvaluateAsExpression=TRUE
  • Expression = RIGHT("0" + (DT_STR, 2, 1252)  MONTH( GETDATE()  ),
    2) + RIGHT("0" + (DT_STR, 2, 1252)  DAY( GETDATE()  ), 2) + (DT_STR, 4,
    1252)  YEAR( GETDATE()  ) + ".xls"

Each time the variable gets referenced the expression is evaluated. Hence, if the package were run today the variable would return the value 03192005.xls, tomorrow it would be 03202005.xls and so on... he could then reference this variable wherever he wanted to in his package and be safe in the knowledge that he was always referring to the correct file.

See, easy! Evaluating expressions for a variable is valuable way to introduce dynamic values into your package. Explore what they can be used for because they're very powerful ( as are property BLOCKED EXPRESSION and could save alot of work in the long term.

-Jamie

 

Published 19 March 2005 16:39 by jamie.thomson

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

jamie.thomson said:

Great article Jamie. I have to admit, I was the original poster to the Beta Site. I played around with Pkg Configurations until I saw this post. The problem I'm facing now is how do I modify this EXPRESSION to return YESTERDAY'S date not today. A getdate()-1 ie.

Expression = RIGHT("0" + (DT_STR, 2, 1252) MONTH( GETDATE() ),
2) + RIGHT("0" + (DT_STR, 2, 1252) DAY( GETDATE()-1 ), 2) + (DT_STR, 4,
1252) YEAR( GETDATE() ) + ".xls"

doesn't seem to do it.
Pls post how to make this happen.
Thanks.
Reggie
March 21, 2005 22:59
 

jamie.thomson said:

Hi Reggie,
I replied to your post on the ng with the answer to this but I'll re-post here.

In the expression I posted before replace
"GETDATE()"
with
"DATEADD("day", -1, GETDATE())"

Which returns yesterday rather than today.

Thanks for visiting! :)

-Jamie
March 21, 2005 23:05
 

jamie.thomson said:

Jamie -
Sucess! I am able to dynamically generate a variable to store a file name based on the current date. We are now facing this issue:

We are using unstructured spreadsheets (.xls) files as our source files. In order to cleanly import this data into our database, we are using the SSIS Package wizard.
The SSIS Package wizard, automatically generates a Source Connection based on the current file: OledbSrc with the ff 'Connection String' Properties:

Data Source=C:\Inetpub\ftproot\ETLBOM\PF032005.xls;Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=EXCEL 8.0;

I then create a variable to store the file name format based on yesterday's date i.e.:
Variable: KeyVal = PFMMDDYY.xls

I go back into the Pacakge (Created by wizard) and modify the OledbSrc conn properties as follows (Replace filename with Variable) to pick up the new daily file:


Data Source=C:\Inetpub\ftproot\ETLBOM\KeyVal.xls;Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=EXCEL 8.0;

When I execute the package, I get the following error bcos the wizard hardcoded the original src file and somehow cannot dynamically read the dynamic file name from the variable:

[Source - Sheet1$ [1]] Error: An OLEDB error has occurred. Error code: 0x80040E37
[Source - Sheet1$ [1]] Error: Failed to open a rowset for Sheet1$. [[Check that the object exists in the database.]]
[DTS.Pipeline] Error: component "Source - Sheet1$" (1) failed validation by returning validation status "VS_ISBROKEN".

Any help to modify the Src Conn (OledbSrc) conn properties created by the Wizard to enable srcing of a dynamic filename will be appreciated.

Thanks.
March 22, 2005 15:00
 

jamie.thomson said:

Sorry for butting into your blog Jamie. :)
From the error, it appears that you're running an older build of SSIS, like beta2 or similar. There were a few issues with property expressions in those builds.
It also appears that you may not be setting up the property expression correctly.
Can you show the property expression you're using?
March 27, 2005 00:54
 

Mark Iwaszko's Blog! said:

November 30, 2005 15:43
 

yen said:

Very Good example ! This blog is very good presented !

Thanks you so much Jamie !

October 6, 2006 14:46
 

IanO said:

It makes sense to me. So I spent most of the day trying to get it to work.

I decided it was simpler to construct the new filename for the FileRename task in a script. It took me a while to discover that even  though the variables had package scope they had to be passed to the script explicitly. Now I enter the FileSystemTask with the RenameFile selected and I'm getting errors because it cannot lock onto the new filename its supposed to be writing!

I am certain that my new name is getting passed from the script to the FileSystemTask  because I can see it in the output window. Why does it want to "lock" on to the new file? I must be confused. Why does it want two connections if it is a FileRename? Okay where do I tell it what the new name is if I don't put it in the connection?

Thanks for reading. Its late and its Friday.

November 17, 2006 21:46
 

prabha said:

First I create one package in SSIS and that ran successfully from the aspx page.

July 24, 2007 06:15
 

aaaaa said:

Using SSIS package wizard ,I read the textfile to Sql table .It works fine.But Through the aspx page ,I want to give the filename as a connection string .Is it Possible.Please help me.

July 24, 2007 06:21
 

uma said:

I used SSIS wizard to import text file to table in database but this wizard ask for fixed source file and I want it to be variable. Please help me on my code in .NET or may be a stored procedure in SQL on how to pass in the package a variable source file. Nid help. Thanks.

July 24, 2007 06:24
 

hellman said:

If you are trying to find "EvaluateAsExpression" it is on the properties tab, not the Variables window.  You can get to it by pressing F4 if you don't already have it popping up as needed.  

I wasted hours trying to find it because I had it shrunk to a single line.  Looking through BOL, web pages, and many other places just kept leading me back to set "EvaluateAsExpression" = True.  But it wasn't plain where to set it.

Looking back, it was plain as day.  Once frustrated, the obvious becomes hidden.

Good post Jamie

Thanks.

July 26, 2007 22:57
 

FP said:

Hey Jamie, Good post man.

Also thanks of Hellman for sharing your experience, I was also set to go to the place where "EvaluateAsExpression=True" was like finding a unicorn :). I am good now. Thanks.

FP

August 8, 2007 10:34
 

MONICA said:

This was great information! However, I have one more question instead of showing a 4 digit year I need a 2 digit year for my file name. Any sugguestions how to?

RIGHT("0" + (DT_STR, 2, 1252)  MONTH( GETDATE()  ),

2) + RIGHT("0" + (DT_STR, 2, 1252)  DAY( GETDATE()  ), 2) + (DT_STR, 4,

1252)  YEAR( GETDATE()  ) + ".xls"

August 28, 2007 16:39
 

jamie.thomson said:

Monica,

Try this:

RIGHT("0" + (DT_STR, 2, 1252)  MONTH( GETDATE()  ),

2) + RIGHT("0" + (DT_STR, 2, 1252)  DAY( GETDATE()  ), 2) + RIGHT((DT_STR, 4,

1252)  YEAR( GETDATE()  ),2) + ".xls"

-Jamie

August 28, 2007 16:47
 

MONICA said:

PERFECT!!!! Thank you Jamie for the help, and for such a rapid response.

August 28, 2007 16:49
 

Zaahid said:

How would you generate a dynamic file name containing a month name eg 3Oct2007

October 4, 2007 13:37
 

Brian at DRG said:

Hi Zaahid,

Look into the CONVERT function when passing a datetime value. You can optionally specify a style parameter. Style value 6 returns something very close to what you want:

select convert(varchar(30), getdate(), 6)

Brian

October 30, 2007 16:52
 

Brian at DRG said:

Hi Jamie,

Any ideas how to use an expression to generate the following format?

XYZ Audit - September 25th 2007

Of course I am pursuing whether the format can be changed first, but in the event it cannot, any suggestions? I did not see a convert style that matches this (with both full month and st/nd/rd/th suffixes). Mabye I will need to roll my own on this one.

Brian

October 30, 2007 16:58
 

jamie.thomson said:

Brian,

This is just a string manipulation problem is it not? Just concatenate the return values from multiple calls to DATEPART. You may also need some nested conditional operators to turn a month number into a month name.

-Jamie

November 6, 2007 14:58
 

Chris said:

Hi Jamie,

I have a datetime column being made in a derived colum. I want to use an expression in the derived column to get the current date, i.e. GETDATE(), but need to strip the time value off of the date. How would one do that? i.e. just return TODAY().

I also will have a couple other places i would like to strip the time so a generalized "time stripping" expression in addition to the TODAY expression would be good to know.

Thanks!

Chris

November 9, 2007 00:45
 

jamie.thomson said:

Hi Chris,

This is a string manipulation problem. Use DATEPART() to get all the bits that you need and concatenate them together.

-Jamie

November 9, 2007 00:59
 

Chris said:

Thanks jamie!

That sure is a pain to get each value (month,day,year) of a date type and then concatenate them together into a string then cast them back to a datetime type. You would have thought they (MS) would have made this easier.

November 9, 2007 15:15
 

Scott said:

I agree with Chris about the pain of string manipulation.

My hope is that in the next SP there would be something like a FormatExpression property for variables in addition to the standard Expression property. It would take a format string (like String.Format) and comma delimited list of variables.  

This would make the date expressions above so much easier to create and debug.

And like String.Format it would use the default code page too. I wonder how many people have hard-coded 1252 into their packages?

November 13, 2007 22:25
 

Kate said:

Hi Jamie. Can you help me with my problem too?

The format of the files is yyyymmdd_MainFile.csv

Now I need to move all the generated files for last month.

How can I do that? If I use the code you posted on top, the program searches for files that matches the specified yyyymmdd. But I'm trying to process a whole month, how should I modify your code?

November 20, 2007 03:04
 

jamie.thomson said:

Kate,

The DATEADD() function should help. Read up about that in the provided Help pages.

-Jamie

November 20, 2007 03:09
 

Kate said:

Hi Jamie

Why is this line not working?

@FileDate + * + @FileName

I want it to return files that satisfies the expression at @FileDate and @FileName regardless of what is in between. I'm not familiar with SQL 2005 SSIS so can you help me again?

Thanks for the first reply by the way. :)

November 20, 2007 07:21
 

jamie.thomson said:

Hi Kate,

Are you trying to concatenate them together? If so, try:

@FileDate + "*" + @FileName

-Jamie

November 20, 2007 12:20
 

Kate said:

I tried using asterisk with quotes but its evaluating it as an string character.

I also tried using an asterisk only but it says "The expression failed evaluation."

I would like to concatenate @FileDate and @FileName and a wildcard.

ex. @FileDate = 11091988_

    @FileName = _Kate

result: Kate_C_Green

I'm using a wildcard so it can return files that match both the @FileDate and @FileName regardless of what is in between. I'm trying to configure my for loop container.

November 21, 2007 01:15
 

jamie.thomson said:

Kate,

OK, I think I see what you're trying to do now. If you want to loop over a group of files then just use the ForEach File enumerator of the ForEach loop.

-Jamie

November 21, 2007 04:25
 

Kate said:

Hi Jamie,

I already have a ForEach Loop container and inside is my file system task.

My file system task searches for a group of files using a particular date.

While my ForEach Loop filters it using their filenames.

On the editor, I tried adding the expression @FileDate + "*" + @FileName on the file textbox. But it returned an error saying file not found when in fact it is there.

I tried evaluating the expression on the property expressions editor but it says "The expression failed evaluation."

How can I filter the group of files uisng their filenames by concatenating variables and wildcards? The editor don't seem to accept it? Any ideas?

November 21, 2007 07:24
 

jamie.thomson said:

Kate,

I'm confused. If the FileSystem task is INSIDE the ForEach loop then why are you trying to use a wildcard. The use of the ForEach loop inherently suggests that you want to operate on each file in turn.

Also...take a look at the MULTIFILE connection manager (http://msdn2.microsoft.com/en-us/library/ms137798.aspx). You may find it useful.

-Jamie

November 21, 2007 15:32
 

Sonali said:

Hi Jamie

Need your help in this.

I have a FTP Task inside a for loop. For loop is for variaous company names. Depending on company name I need to FTP files to different FTP servers. How can I achieve this dynamically?

Thank s in advance

January 10, 2008 06:41
 

Nev said:

I'm dynamically building a filename with a date component in it using Expressions to open an Excel file via an OLEDB source connection.  All well and good.

Alas the workbook is also dated, e.g "Sep 07", and there doesn't seem to be a way of setting the "Name of the table or the view" attribute on the OLE DB Source via an expression.  I have the calculated value and stored it in a variable but can find no way to assign it via an expression to this attribute - am I missing something or is this an oversight by M$?

January 10, 2008 16:36
 

jamie.thomson said:

Nev,

Yeah, it looks like an oversight. I don't know much (anything???) about accessing Excel from the OLE DB Source. Can you use some sort of SQL Statement ather than just defining a worksheet name? I suspect you can given that this is using OLE DB.

-Jamie

January 10, 2008 16:58
 

mpatel said:

I am trying to insert the number of records in the file name of a text file that I have set to automatically populate with results from a query.  I have been stuck on this for a couple of weeks now.  Does anyone know the best way to do this?

January 28, 2008 21:43
 

Clare said:

Is there a way to conditionally load files using Foreach File Enumerator? For example, I have files with timestamp in the file names and I want to load only files before certain timstamp.

February 4, 2008 15:18
 

jamie.thomson said:

Clare,

No, there's no way to do that. It would be nice though wouldn't it?

There's an easy workaround though. Inside the ForEach loop check the iterated value to see if it complies with your criteria. If it doesn't, don't process it. You'll need conditional precedence constraints for that.

-Jamie

February 4, 2008 15:25
 

Clare said:

Jaime,

Thank you for the quick reply.. before I saw you note, I tried another way and it dose not work

I set the following expression for "FileSpec" property in Foreach Loop

@[User::CountFileName] < ("COUNT" + @[User::FileStopTimestamp]  + ".TXT")?  @[User::CountFileName]  : "wait.txt"

@[User::CountFileName]: the variable to hold file name in each loop

@[User::FileStopTimestamp]: the variable to hold the cut off timestamp

I thought the above expression would return a  file name if the file name is smaller than the cut off file name. While I evaluated the expression it did what I expected. But when I run it, it seems only get evaluated once and use that value for all the entire loop. Is that something by design? Can we dynamically reset "FileSpec" in a loop?

Back to your suggestion, do I need a script to check file name?

February 4, 2008 18:40
 

jamie.thomson said:

Clare,

"But when I run it, it seems only get evaluated once and use that value for all the entire loop. Is that something by design? Can we dynamically reset "FileSpec" in a loop?"

Yes, that's by design. It populates a collection once and then loops over that collection.

"Back to your suggestion, do I need a script to check file name? "

No, you need conditional precedence constraints: http://search.live.com/results.aspx?q=conditional+precedence+constraints&form=QBJK&q1=macro%3Ajamiet.ssis

-Jamie

February 4, 2008 18:46
 

Clare said:

Jaime,

Thanks a lot! It works but I have to put a dummy job before my data flow job so that the precedence constraint can be set before the data flow job

Expression in the constraint.

@[User::CountFileName] < ("COUNT" + @[User::FileStopTimestamp]  + ".TXT")

February 4, 2008 19:24
 

jamie.thomson said:

Clare,

Yes, that's completely correct. I typically use an empty sequence container for this scenario.

-Jamie

February 4, 2008 20:05
 

prasad said:

i want to give complete filepath dynamic.

filename is fixed.

filepath value is present in user variable @[User::FileShareLoc] .

@[User::FileShareLoc]  + "\\ABC.csv"

its giving error

how to write expression.

February 15, 2008 09:03
 

Felipe Maurer said:

Hi,

I'm trying to set the Destination Name of e File System Task using a variable, but I get the error "The wrapper was unable to set the value of the variable specified in the ExecutionValueVariable property. " I'm guessing it has to do with the scope of the variable but I have no idea how to fix it. Any ideas?

February 28, 2008 00:30
 

Merl said:

Hi Jamie - thanks very much for all the work you do on this blog; I've had to seriously ramp up my expertise on SSIS and this has been invaluable information.

One related topic I have run into, and I wonder if you have any insight: order of evaluation for related variables that are set by expressions. I had this intractable bug in a package that dropped data out to several files, where the file names contained a date stamp.

The original design was to make one variable containing a formatted datestamp as some long expression like

(DT_WSTR,4)YEAR(@[System::StartTime]) +

RIGHT("00" + (DT_WSTR,2) MONTH(@[System::StartTime]),2) +

RIGHT("00" + (DT_WSTR,2) DAY(@[System::StartTime]),2)  +

RIGHT("00" + (DT_WSTR,2) DATEPART("Hh",@[System::StartTime]) , 2)  +

RIGHT("00" + (DT_WSTR,2) DATEPART("mi",@[System::StartTime]) , 2)  

then, to avoid repeating that whole beast, the file names were set with separate variables like

@OutputFolder + @PropertiesFilePrefix + "_" + @datestamp   + ".txt"

I was noticing the job failing, and found that the datestamps were not being consistently set in the file names, so sometimes a file would get the right stamp, and sometimes not.

I had a hunch it has to do with the order of evaluation of the variables' expressions, so I eliminated the @datestamp variable and copied the whole expression into each file name variable. That seems to have fixed the issue. Have you run into anything like this?

April 2, 2008 00:20
 

jamie.thomson said:

Merl,

This sounds like it should work.

Are you sure you had EvaluateAsExpression=TRUE on the @datestamp variable?

-Jamie

April 2, 2008 02:25
 

Merl said:

Yup, definitely. The strange behavior was that in one execution of the package, the datestamp would make it, correctly, all the way into some output file names, but other file names would come out wrong. Strange.

April 2, 2008 22:40
 

mg1 said:

I am new to SSIS and I have what I thought was a simple operation to accomplish. I need to capture the date when a package starts and use it later in a script task that resides in a foreach loop. The first task in the package is a script task and I am using the expression editor to assign a value to a package variable (used the above example -works well!). I am trying to access that package variable in the second script task but I get the "failed to lock variable" error.

April 8, 2008 14:57
 

jamie.thomson said:

mg1,

Where else are you accessing that variable? Are you accessing it in the first script task?

-Jamie

April 8, 2008 15:01
 

Shaw said:

I have seen everybody using the RIGHT function. Can the LEFT function be used?! Very silly to ask, but i tried using LEFT and received an error saying function not defined or something along the lines; using RIGHT worked just fine. What gives?!

April 25, 2008 15:23
 

jamie.thomson said:

Shaw,

There isn't a LEFT function. the reason is that the same can be achieved with SUBSTRING.

Don't shoot the messenger :)

-Jamie

April 25, 2008 15:27
 

Shaw said:

Thanks Jamie!!!!!! I was about to pull out my hair cause I everything else looks good and i didn't suspect the LEFT function to be the issue. Hey you have an awesome blog going! Love it!

April 25, 2008 17:09
 

Shaw said:

is there a list of functions that can be used in Expression out there somewhere?

April 25, 2008 17:14
 

Shaw said:

This is the sql equivalent of what i am trying to do

DECLARE @STR VARCHAR(10)

SET @STR = '1234.CSV'

SELECT CHARINDEX('.', @STR), SUBSTRING(@STR, 1, charINDEX('.', @STR)-1)

April 25, 2008 17:14
 

Shaw said:

This is the sql equivalent of what i am trying to do

DECLARE @STR VARCHAR(10)

SET @STR = '1234.CSV'

SELECT CHARINDEX('.', @STR), SUBSTRING(@STR, 1, charINDEX('.', @STR)-1)

April 25, 2008 17:15
 

jamie.thomson said:

Shaw,

The list of available fuctoins is in the top right hand corner of the expression editor.

Does FINDSTRING() do what you want?

-Jamie

April 25, 2008 17:19
 

Shaw said:

Yay! It did! Thanx Jamie.

On a side note, while editing the expression for variables, I do not seem to find the Expression Editor or could I be any more dumber!! LoL

April 25, 2008 17:28
 

jamie.thomson said:

Shaw,

Install SP1 and it'll magically appear!

-Jamie

April 25, 2008 17:33
 

Shaw said:

Thanks Jamie!

April 25, 2008 17:56
 

Jim said:

Hi this is a great but i have one problem am trying to solve my self for most of the file name you looking at name with dates in them. But with my problem i have the week number as part of the extension an example of this is

filename.A16 so the file name would look like that SampleFile.A18 where 18 is the week number.

Is it possible to create an expression to do this i tried but am not having much hope..

April 28, 2008 15:26
 

jamie.thomson said:

Jim,

You're going to have to use the DATEPART function (http://msdn2.microsoft.com/en-us/library/ms137586.aspx) to get the week number.

-Jamie

April 29, 2008 11:59
 

Leandro (Brazil) said:

Hi Jamie,

First of all thanks for your blog... very useful!

Well, I'm looking for some example or tutorial of how to make an optimized package on SSIS to keep two tables (different servers) updated. Can you help me?

Many thanks so far!

-Leandro

May 16, 2008 20:43
 

jamie.thomson said:

Leandro,

If you want to use SSIS to do this then you might find this useful: http://blogs.conchango.com/jamiethomson/archive/2006/09/12/SSIS_3A00_-Checking-if-a-row-exists-and-if-it-does_2C00_-has-it-changed.aspx

although you might want to explore the use of replication for this instead.

Regards

Jamie

May 19, 2008 10:34
 

Sean Hennessy said:

This is a great thread but i need a bit of help.

I have a flat file which i get exported upto an FTP server daily with details of the days phone log files. They are pushed up at 10.00pm everynight so im writing an SSIS package to grab the file up there and import the data into the SQL database i have. then to delete the file up there..

The problem i have is that the flat file name is in the format Record.yyyymmddXXXXXXX where X is a random number.

Is there any way i can use a wildcard in the connectionstring to the file to open the file up there?

Regards

Sean

July 10, 2008 12:54
 

jamie.thomson said:

Sean,

Try using the MULTIFLATFILE adapter.

-Jamie

July 10, 2008 13:05
 

Sean said:

jamie..

Whats the best way to implement it?

Ive tried adding the multiflatfile but it doesn't recognise my file..

Cheers

Sean

July 10, 2008 14:29
 

jamie.thomson said:

Sean,

Not sure why it wouldn't work.

If it doesn't work for you then maybe try the File enumerator in the ForEach loop. You can use wildcards in that and if you only have one file then the ForEach loop will only iterate once.

Regards

Jamie

July 10, 2008 14:37
 

Emily.Jones said:

Hi Jamie! It's your pal Emily :) Your post has really helped me out like always! I was stuck on this thing for 2 days, i should have looked you up earlier...

July 22, 2008 16:57
 

jamie.thomson said:

Ha, yes. You definitely should have done jonesy! :)

July 22, 2008 17:00
 

asentell said:

Jamie,

Is there any way to tell SSIS when to re-evaluate variable expressions? For example: I have a variable that defines a filename using a date and time expression (filename_yyyymmdd_hhmm). When I go back and try to do something with that file in a later step and the time has changed, according to SSIS the file does not exist. Very annoying!

Thanks,

Aaron

July 29, 2008 13:58
 

jamie.thomson said:

Aaron,

That's jsut the way it works. if you want to persist the value then you'l have to create a new variable that has EvaluateAsExpression=FALSE and set it to the value of your existing variable using a script task.

-Jamie

July 30, 2008 10:03
 

jbanko said:

OK, so I have the correct path for a file, sourcePath. Now how do I use it in for instance a BulkInsert Task? When I put it in as the source connection, I get the error message that the connection <sourcePath> is invalid. I can't figure out how to configure a a file connection using a variable or expression. They want a SPECIFIC location (path)?

Thx,

Joe B

August 5, 2008 19:47
 

jamie.thomson said:

Hi Joe,

You will have to apply an expression to the ConnectionString property of the connection manager that is being used by the Bulk Insert Task.

If anything isn't clear about that just reply here.

-jamie

August 6, 2008 11:13
 

David said:

If I want to open a file where the name changes every 5 minutes but always contains a "ante", how would I do that?

August 12, 2008 16:34
 

Rabindra Jha said:

Hi,

My FileName  is in format yyyymmdd.txt I want to retrive the File between specific Date.for example, I want to retrive the file  between the date  20080906 to 20080908. How Can I Do it. Please suggest me the expression.

September 8, 2008 07:20
 

Elaine said:

Jamie,

Excellent site.  I got a much better handle on SSIS thru sites like yours.  Very helpfu.

I have a task to do that is very similar to what Kate wanted to achieve.  I need to automate a daily import process that takes a flat file with a file name that includes today's date and a time stamp and import the data into the database.  The file name looks like "Mainfile_20081101_012345.dat" so I tried to use either a script task to match and find the file or set the expression in the connection manager both with a "*" wildcard for the time stamp part but none of them worked.  I created a global variable "FileName" to do this so the update can be passed on to all tasks in the pkg.

To match the date part of the file name was simple but when I use the "*" wildcard, it always evaluated as "Mainfile_20081101_*.dat" and the pkg failed because the file didn't exist.  The only way I could get the package to work was to copy the exact file name and run with it.  It seems to me that wildcard isn't supported in SSIS.  Since this stopped me from being able to automate the process so I'd really like to find a solution to it.

Since I only need to process one to two files per day, it is not necessary for me to use For Loop to process all the file in the folder.  Do you have any workaround to this?  

Thanks much in advance.

November 5, 2008 20:11
 

jamie.thomson said:

Elaine,

Take a read of this:

Processing data from multiple files all at once

(http://blogs.conchango.com/jamiethomson/archive/2006/10/14/SSIS_3A00_-Processing-data-from-multiple-files-all-at-once.aspx)

-Jamie

November 6, 2008 09:56
 

Rick said:

Great blog!  I've got a series of files with the follwing naming format:

IDNumber_Q1.xml

IDNumber_Q2.xml

IDNumber_Q3.xml

...

IDNumber is the only variable part of the file naming structure. The remaining is constant. Using the for-each file enumerator loop, for the file name expression, I try using *_Q*.xml, but get a file not found error. I can use *_Q1.xml and it works fine for the Q1 files, but it won't process the second wildcard. I've even tried using the *_Q?.xml format and it gives the same error. Any ideas? I'd prefer not to create seperate loop processes for each Q* file as the format and contents are consistent and can be handled in the same loop process if the files can be identified.

November 6, 2008 18:31
 

jamie.thomson said:

Rick,

Hmm...that doesn't sound good. Sounds like a bug in fact.

As a workaround you may wish to take a look at this:

Processing data from multiple files all at once

(http://blogs.conchango.com/jamiethomson/archive/2006/10/14/SSIS_3A00_-Processing-data-from-multiple-files-all-at-once.aspx)

-jamie

November 10, 2008 09:29

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication

Powered by Community Server (Personal Edition), by Telligent Systems