如何使用SSIS表达式获取上周五的日期? 使用以下表达式:
RIGHT("0" + (DT_WSTR, 2) MONTH(dateadd("d", -1, getdate())), 2)
+ RIGHT("0" + (DT_WSTR, 2) DAY(dateadd("d", -1, getdate())), 2)
+ RIGHT("1"+(DT_WSTR, 4) YEAR(dateadd("d", -1, getdate())),2)+ ".csv"
上述表达式的输出为021014.csv
答案 0 :(得分:3)
这也可以使用:
@[User::Destination] + "_"+ (DT_WSTR,20)
(
DATEPART("dw",GETDATE())==1? RIGHT("0"+(DT_WSTR,2)Month (DATEADD ("D", - 1 GETDATE()) ), 2)
+
RIGHT ("0"+(DT_WSTR,2)DAY(DATEADD("D",-1,GETDATE())),2)
+
RIGHT("1"+(DT_WSTR,4)YEAR(DATEADD("D",-1,GETDATE())),2)
:
DATEPART("dw",GETDATE())==2? RIGHT("0"+(DT_WSTR,2) Month(DATEADD("D",-1,GETDATE())),2)
+
RIGHT ("0"+(DT_WSTR,2)DAY(DATEADD("D",-2,GETDATE())),2)
+
RIGHT("1"+(DT_WSTR,4)YEAR(DATEADD("D",-1,GETDATE())),2)
:
DATEPART("dw",GETDATE())==3? RIGHT("0"+(DT_WSTR,2) >Month(DATEADD("D",-1,GETDATE())),2)
+
RIGHT ("0"+(DT_WSTR,2)DAY(DATEADD("D",-3,GETDATE())),2)
+
RIGHT("1"+(DT_WSTR,4)YEAR(DATEADD("D",-1,GETDATE())),2)
:
DATEPART("dw",GETDATE())==4? RIGHT("0"+(DT_WSTR,2) >Month(DATEADD("D",-1,GETDATE())),2)
+
RIGHT ("0"+(DT_WSTR,2)DAY(DATEADD("D",-4,GETDATE())),2)
+
RIGHT("1"+(DT_WSTR,4)YEAR(DATEADD("D",-1,GETDATE())),2)
:
DATEPART("dw",GETDATE())==5? RIGHT("0"+(DT_WSTR,2) >Month(DATEADD("D",-1,GETDATE())),2)
+
RIGHT ("0"+(DT_WSTR,2)DAY(DATEADD("D",-5,GETDATE())),2)
+
RIGHT("1"+(DT_WSTR,4)YEAR(DATEADD("D",-1,GETDATE())),2)
:
DATEPART("dw",GETDATE())==6? RIGHT("0"+(DT_WSTR,2)Month (DATEADD("D",-1,GETDATE())),2)
+
RIGHT ("0"+(DT_WSTR,2)DAY(DATEADD("D",-6,GETDATE())),2)
+
RIGHT("1"+(DT_WSTR,4)YEAR(DATEADD("D",-1,GETDATE())),2)
:
DATEPART("dw",GETDATE())==7? RIGHT("0"+(DT_WSTR,2) >Month( DATEADD(" D",-1, GETDATE() )),2)
+
RIGHT ("0"+(DT_WSTR,2)DAY(DATEADD("D",-7,GETDATE())),2)
+
RIGHT("1"+(DT_WSTR,4)YEAR(DATEADD("D",-1,GETDATE())),2)
: "" )
+".csv"
答案 1 :(得分:0)
这是使用T-SQL,您仍然需要转换为SSIS。这更像暗示了一个答案。但无法将其纳入评论。
DECLARE @CurrentDate DATE = '02/15/2014' --Saturday
--Returns Date for Friday that was last week. When current date is Saturday will return Friday that was 1 week ago.
SELECT DATEADD(dd,-DATEPART(weekday,@CurrentDate)-1,@CurrentDate) --Output: 2014-02-07
--Returns Date for most recent Friday.
SELECT DATEADD(dd,-(DATEPART(weekday,@CurrentDate)%7+1),@CurrentDate) --Output: 2014-02-14
SET @CurrentDate = '02/11/2014' --Tuesday
SELECT DATEADD(dd,-DATEPART(weekday,@CurrentDate)-1,@CurrentDate) --Output: 2014-02-07
SELECT DATEADD(dd,-(DATEPART(weekday,@CurrentDate)%7+1),@CurrentDate) --Output: 2014-02-07
你需要弄清楚你星期五的要求是什么,是上周末的星期五,还是上个星期五,而是本周或之前的星期五。