Sunday, February 12, 2012

Casting...

I've got an ftp task that will be downloading a couple of files each night. today they're called

blah20060830blah

the date value in the middle changes each day. I'm trying to adjust this value with an expression. The expression doesn't want to cast my getdate function into a string that this property will accept. I know i'm missing something stupid.

Thank you

It'd help if you posted your expression and the error that you're getting.

-Jamie

|||Sorry

the expression
(DT_STR) GETDATE()

generates this:
Attempt to parse the expression "(DT_STR) GETDATE()" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

I'm no genius when it comes to making these expressions, and was unable to find a source on the msn site

Thanks again|||

All the source you need is in BOL. And in this case the syntax for the cast is given in the expression editor.

You need:

(DT_STR, 100, 1252)GETDATE()

-Jamie

|||What is BOL?

I put your suggestion into the expression builder, but got the following error

Expression cannot be evaluated.

The expression "(DT_STR, 100, 1252)GETDATE()" has a result type of "DT_STR", which cannot be converted to a supported type.

Do I need to put more in the expression builder?|||

killerless wrote:

What is BOL?

Sorry. Books Online. i.e. The help pages that you get with SQL Server.

killerless wrote:

I put your suggestion into the expression builder, but got the following error

Expression cannot be evaluated.

The expression "(DT_STR, 100, 1252)GETDATE()" has a result type of "DT_STR", which cannot be converted to a supported type.

Do I need to put more in the expression builder?

Hmmm...are you trying to add this as anew column or replace an existing one? If the latter, change it so that you are adding it as a new column.

-Jamie

|||Maybe I'm completely missing the boat here.

in an ftp task, there is a property called "Remote Path" As I understand, this designates what the path and filename of the remote file to be downloaded.

Here's my leap of understanding. I want that value to change daily, I'm assuming that I can define this using an expression. I will concat the parts of the string in the expression builder that don't change daily, to the part that i'm trying to generate right now (which is based on the date)

I am double clicking on the ftp task, setting appropriate properties, then going to the expression section and trying to set the remote path w/ an expression using the expression builder. I'm literally cutting and pasting what you typed in to the expression text area and trying to see if it will evaluate the expression as a string.

As far as I know there are no columns involved. (I will check out the BOL)

Thanks|||

Oh OK. Sorry, I thought you were in a Derived Column Component (which you are not).

Your approach is the corect one. its jsut going to take some debugging that's all.

The Expression Editor itself has some really useful visual aids as to the syntax of all the functions etc... Loom in the box in the top-right of the expressoin editor.

-Jamie

|||I think i'm getting there i will post when i figure this out...|||There's got to be a better way!!!!

DATEPART("weekday", GETDATE()) == 2 ?
"positions_01_CLARENROAD_" + (DT_WSTR,10)(DatePart("yyyy", DATEADD( "day", -3, getdate() ) ) ) +
(
DatePart("mm", DATEADD( "day", -3, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("mm", DATEADD( "day", -3, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("mm", DATEADD( "day", -3, getdate() ) ) )
) +
(
DatePart("dd", DATEADD( "day", -3, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("dd", DATEADD( "day", -3, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("dd", DATEADD( "day", -3, getdate() ) ) )
)
:
"positions_01_CLARENROAD_" + (DT_WSTR,10)(DatePart("yyyy", DATEADD( "day", -1, getdate() ) ) ) +
(
DatePart("mm", DATEADD( "day", -1, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("mm", DATEADD( "day", -1, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("mm", DATEADD( "day", -1, getdate() ) ) )
) +
(
DatePart("dd", DATEADD( "day", -1, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("dd", DATEADD( "day", -1, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("dd", DATEADD( "day", -1, getdate() ) ) )
)
+ "_today.gz.file.asc"

will successfully determine the last day of trading, and afix it to the middle of the string. Can you make temporary variables in these expressions that would probably cut this in half
|||How can I set this value to a variable, so that I can use it in other expressions?|||

killerless wrote:

How can I set this value to a variable, so that I can use it in other expressions?

Good idea!

There is a property of the variable called EvaluateAsExpression. Set this proeprty to false and then paste your expression into the Expression property.

I talk about this a bit here:

Using variables to store expressions
(http://blogs.conchango.com/jamiethomson/archive/2005/12/05/2462.aspx)

Evaluating variables as expressions
(http://blogs.conchango.com/jamiethomson/archive/2005/03/19/1163.aspx)

-Jamie

|||AWESOME, thanks a lot, i'm looking forward to the day when the variable expression can be created w/ the expression builder. (I'd settle for a text area a this point)

Is it possible to call a stored procedure? From a expression?

Thanks :)|||so...if the remote variable is now being set w/ an expression, why can't I leave the field blank? Aside from making lost of extra variables is there any advantage to putting these strings in variable derived from my date variable?

Thanks|||

killerless wrote:

AWESOME, thanks a lot, i'm looking forward to the day when the variable expression can be created w/ the expression builder. (I'd settle for a text area a this point)

Install Sp1 and you'll be able to

killerless wrote:

Is it possible to call a stored procedure? From a expression?

No! Sorry.

-Jamie

No comments:

Post a Comment