我有一个每天运行的ssis包。这个ssis包有几个执行sql任务,它们为昨天的事务加载数据。实施例
INSERT INTO Shipped
(Div_Code, shipment_value, ship_l_id, shipped_qty, shipped_date, whse_code,
ord_id, ship_id, ship_l_ord_l_id, Created_date)
select ord.DIV_CODE as div_code, ship.SHIPMENT_VALUE as shipment_value, ship_l.SHIP_L_ID as ship_l_id,
ship_l.SHIPPED_QTY as shipped_qty, ship.SHIPPED_DATE as shipped_date, ship.WHSE_CODE as whse_code,
ord.ORD_ID as ord_id, ship.SHIP_ID as ship_id, ship_l.ord_l_id as ship_l_ord_l_id, Getdate() as Created_date
FROM SHIP ship, ORD ord,
SHIP_L ship_l
WHERE ship.SHIPPED_DATE=(dateadd(day, -1, CONVERT(VARCHAR(10),GETDATE(),120)))
and ship.WHSE_CODE='WPP' and ord.ORD_ID=ship.ORD_ID
and ship.SHIP_ID=ship_l.SHIP_ID
所有执行sql任务都有如上查询的查询。在某些查询中,我们有日期过滤器,它会加载昨天的数据。防爆。一个查询有ship.SHIPPED_DATE =(dateadd(day,-1,CONVERT(VARCHAR(10),GETDATE(),120)))。其他一些查询有ord.trans_date =(dateadd(day,-1,CONVERT(VARCHAR(10),GETDATE(),120)))。这个包每天通过sql server job运行,所以它加载昨天的数据。现在,如果我想参加任何特定日期,我们怎样才能从ssis中获益?我是SSIS的新手。任何人都可以指导我实现这个目标吗?
提前致谢
答案 0 :(得分:0)
您可以运行包来更改日期条件。
INSERT INTO Shipped (Div_Code, shipment_value, ship_l_id, shipped_qty, shipped_date, whse_code,
ord_id, ship_id, ship_l_ord_l_id, Created_date) select ord.DIV_CODE as div_code, ship.SHIPMENT_VALUE as shipment_value, ship_l.SHIP_L_ID as ship_l_id, ship_l.SHIPPED_QTY as shipped_qty, ship.SHIPPED_DATE as shipped_date, ship.WHSE_CODE as whse_code, ord.ORD_ID as ord_id, ship.SHIP_ID as ship_id, ship_l.ord_l_id as ship_l_ord_l_id, Getdate() as Created_date from SHIP ship, ORD ord, SHIP_L ship_l where ship.SHIPPED_DATE=(dateadd(day, -1, CONVERT(VARCHAR(10),GETDATE(),120))) and ship.WHSE_CODE='WPP' and ord.ORD_ID=ship.ORD_ID and ship.SHIP_ID=ship_l.SHIP_ID
使用查询中的指定日期更改getdate()并执行包
答案 1 :(得分:0)
请参阅以下您可以使用的步骤,这很简单
date
ExecuteSql
任务,编写要添加的查询或
使用getdate()
WHERE ship.SHIPPED_DATE =(dateadd(day,-1, CONVERT(VARCHAR(10),GETDATE(),120)))
使用下面的
WHERE ship.SHIPPED_DATE=(Select column from tablename)
逻辑:默认情况下,您的查询会从表中获取getdate()
,但如果您使用特定表手动更新表,则您的包将以特定日期执行
我们可以通过其他方式实现这一点,比如使用环境变量,但我认为上面的过程适合你。