SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Date in Expression Builder


Date in Expression Builder

Author
Message
Tim Riley-492074
Tim Riley-492074
Old Hand
Old Hand (325 reputation)Old Hand (325 reputation)Old Hand (325 reputation)Old Hand (325 reputation)Old Hand (325 reputation)Old Hand (325 reputation)Old Hand (325 reputation)Old Hand (325 reputation)

Group: General Forum Members
Points: 325 Visits: 147
I'm trying to build an expression for the remote path in an FTP Task. When I enter

"/out/export/" + (DT_WSTR, 4) YEAR( GETDATE() ) + RIGHT( "0" + (DT_WSTR, 2) MONTH( GETDATE() ) , 2 ) everything work fine.

However, when I add + RIGHT("0" + (DT_WSTR,2) DatePart("dd", -1, GETDATE()),2) I get a truncation error. What I'm trying to do is make sure that I have a two digit day.

Any help would be appreciated.

Tim
Adam Haines
Adam Haines
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6082 Visits: 3135
The easiest method would be to make a variable that evaulates as an expression. Your variable expression should look like this

"/out/export/" + RIGHT("0" + (DT_WSTR,2) datepart("d",Dateadd("dd", -1, GETDATE())),2)


Then in the connection string expression just call the variable.

RIGHT("0" + (DT_WSTR,2) DatePart("dd", -1, GETDATE()),2)

This will always produce errors because you are providing to many parameters for datepart. The datepart parameters are (datepart,date). I think you are tying to use dateadd which requires three parameters (interval,numer, date).

I resolved what I believe you were trying to accomplish in the code block above.



My blog: http://jahaines.blogspot.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search