最后的办法就是从数据窗口的第一条循环最后一条,逐一判断.例如 int i int id string flag for i = 1 to dw_1.rowcount() id = dw_1.getitemnumber(i , "id") //id = dw_1.getitemstring(i , "id") select flag into :flag from tb where id = :id; if flag = ... update tb set ... where id = :id; end for
最好的办法就是从数据窗口的第一条循环最后一条,逐一判断. 例如 int i int id string flag for i = 1 to dw_1.rowcount() id = dw_1.getitemnumber(i , "id") //id = dw_1.getitemstring(i , "id") select flag into :flag from tb where id = :id; if flag = ... update tb set ... where id = :id; end for
这是以前用的etl语句 ---------------------------------------------------传输商品维度表 --------------把数据写入临时表 select h_id ,type_name , h_name,h_bak1,h_bak2, h_exist , h_isbn ,h_input_price,h_input_date,a.last_mod_date as 'db_product_date' , b.last_mod_date as 'dz_type_date' into #csjydb_spwd from srv_lnk.book.dbo.db_product a,srv_lnk.book.dbo.dz_type b where a.h_type=b.h_type and convert(char(10),h_input_date,21)>='2008-01-01' and convert(char(10),h_input_date,21)<='2008-03-01' ------------------进行判断 if (select count(*) from #csjydb_spwd)= (select count(*) from srv_lnk.book.dbo.db_product a,srv_lnk.book.dbo.dz_type b where a.h_type=b.h_type and convert(char(10),h_input_date,21)>'2008-01-01' and convert(char(10),h_input_date,21)<='2008-03-01')
begin insert into spwdb select * from #csjydb_spwd where h_id not in (select h_id from spwdb ) select '*********************已经传输商品维度表'+cast((select count(*) from #csjydb_spwd) as varchar(100) )+'行' as '恭喜' ----------------------------------- 增量更新 if exists (select 1 from #csjydb_spwd a, spwdb b where a.h_id=b.h_id and (a.db_product_date<>b.db_product_date or a.dz_type_date<>b.dz_type_date)) begin update spwdb set h_id=b.h_id,type_name=b.type_name,h_name=b.h_name,h_bak1=b.h_bak1 ,h_bak2=b.h_bak2 ,h_exist=b.h_exist,h_isbn=b.h_isbn ,h_input_price=b.h_input_price,h_input_date=b.h_input_date from spwdb a, #csjydb_spwd b where a.h_id=b.h_id and (a.db_product_date<>b.db_product_date or a.dz_type_date<>b.dz_type_date)end end else begin select '商品维度表的传输出现异常,传输停止!!!!!' as '警告' return end go
数据流, 在定义源的时候, Data Access mode 中选择 "SQL Command" 然后在下面的 "SQL Command Text" 中输入查询语句, 用 ? 表示参数(例如 select * from sys.tables where modify_date between ? and ?) 然后点 "Parameters" 为参数设置值, 你可以用固定值, 也可以用变量 一般用变更啦, 这样你可以为变量值设置一个表达式, 就可以通过表达式动态算时间了. 甚至这个变量值可以是从数据库中读出来的(使用控制流的执行SQL任务)
测试数据:Excel数据源A: A B 2008-01-01 1 2008-01-02 2 Excel数据源B: A B AA 1 BB 2 需求:通过连接 写入数据库 数据库的表结构 a DATETIME, b DOUBLE PRECISION,c NVARCHAR(255)描述:拖入【数据流任务】到【控制流】,双击进入【数据流】,拖入两个【excle数据源】,拖入【排序】,然后拖入【合并连接】这时候,拖入【查找】和【sqlcommand】,进行更新插入。我现在的问题是,能不能通过处理,按照时间段,就像我们查询一样,输入开始时间和结束时间,就把时间断内的数据给抽取出来了,请老大明示
在数据源里选择sql命令,输入 脚本: select * from jxbookall.dbo.yw_px where convert(char(10),input_date,21)>=? and convert(char(10),input_date,21)<=?,点击【参数】,在变量栏点击新增以后,把参数的值设置成空,然后在控制流里拖入【sql任务】,怎么来传参数,请老大给出操作过程。测试了好多遍都失败,现在大概就是两种1、取getdate()得到今天时间,再用dateadd来算从今天起要抽取多少天以前的数据, 2、第二种就是从数据库里读取,到时候只要修改数据库里日期就行,请老大给出操作过程,谢谢
似乎还是不必要这样做,直接 db--dw 就可以了的
int i
int id
string flag
for i = 1 to dw_1.rowcount()
id = dw_1.getitemnumber(i , "id") //id = dw_1.getitemstring(i , "id")
select flag into :flag from tb where id = :id;
if flag = ...
update tb set ... where id = :id;
end for
int i
int id
string flag
for i = 1 to dw_1.rowcount()
id = dw_1.getitemnumber(i , "id") //id = dw_1.getitemstring(i , "id")
select flag into :flag from tb where id = :id;
if flag = ...
update tb set ... where id = :id;
end for
---------------------------------------------------传输商品维度表
--------------把数据写入临时表
select h_id ,type_name , h_name,h_bak1,h_bak2, h_exist ,
h_isbn ,h_input_price,h_input_date,a.last_mod_date as 'db_product_date' ,
b.last_mod_date as 'dz_type_date' into #csjydb_spwd
from srv_lnk.book.dbo.db_product a,srv_lnk.book.dbo.dz_type b where a.h_type=b.h_type
and convert(char(10),h_input_date,21)>='2008-01-01'
and convert(char(10),h_input_date,21)<='2008-03-01'
------------------进行判断
if
(select count(*) from #csjydb_spwd)=
(select count(*) from srv_lnk.book.dbo.db_product a,srv_lnk.book.dbo.dz_type b where a.h_type=b.h_type
and convert(char(10),h_input_date,21)>'2008-01-01'
and convert(char(10),h_input_date,21)<='2008-03-01')
begin
insert into spwdb
select * from #csjydb_spwd where h_id not in (select h_id from spwdb ) select '*********************已经传输商品维度表'+cast((select count(*) from #csjydb_spwd) as varchar(100) )+'行' as '恭喜'
----------------------------------- 增量更新
if exists
(select 1 from #csjydb_spwd a, spwdb b where a.h_id=b.h_id
and (a.db_product_date<>b.db_product_date or a.dz_type_date<>b.dz_type_date))
begin
update spwdb set h_id=b.h_id,type_name=b.type_name,h_name=b.h_name,h_bak1=b.h_bak1 ,h_bak2=b.h_bak2 ,h_exist=b.h_exist,h_isbn=b.h_isbn ,h_input_price=b.h_input_price,h_input_date=b.h_input_date
from spwdb a, #csjydb_spwd b where a.h_id=b.h_id
and (a.db_product_date<>b.db_product_date or a.dz_type_date<>b.dz_type_date)end
end
else
begin
select '商品维度表的传输出现异常,传输停止!!!!!' as '警告'
return
end
go
不提交更新的话,ssis 也判断不了你是否更改了的啊
你理解错误,他所说的dw不是pb的datawindow 是数据仓库dataware,db到dw需要etl数据抽取的过程,etl是需要工具的,比如存储过程或者ssis之类的工具
http://blog.csdn.net/zjcxc/archive/2009/03/10/3975644.aspx
http://blog.csdn.net/zjcxc/archive/2009/02/23/3924959.aspx
http://blog.csdn.net/zjcxc/archive/2009/03/10/3975644.aspx
http://blog.csdn.net/zjcxc/archive/2009/02/23/3924959.aspx
http://blog.csdn.net/zjcxc/archive/2006/09/10/1202876.aspx
数据流, 在定义源的时候, Data Access mode 中选择 "SQL Command"
然后在下面的 "SQL Command Text" 中输入查询语句, 用 ? 表示参数(例如 select * from sys.tables where modify_date between ? and ?)
然后点 "Parameters" 为参数设置值, 你可以用固定值, 也可以用变量
一般用变更啦, 这样你可以为变量值设置一个表达式, 就可以通过表达式动态算时间了. 甚至这个变量值可以是从数据库中读出来的(使用控制流的执行SQL任务)
A B
2008-01-01 1
2008-01-02 2
Excel数据源B:
A B
AA 1
BB 2 需求:通过连接 写入数据库 数据库的表结构 a DATETIME, b DOUBLE PRECISION,c NVARCHAR(255)描述:拖入【数据流任务】到【控制流】,双击进入【数据流】,拖入两个【excle数据源】,拖入【排序】,然后拖入【合并连接】这时候,拖入【查找】和【sqlcommand】,进行更新插入。我现在的问题是,能不能通过处理,按照时间段,就像我们查询一样,输入开始时间和结束时间,就把时间断内的数据给抽取出来了,请老大明示
select * from jxbookall.dbo.yw_px where convert(char(10),input_date,21)>=? and
convert(char(10),input_date,21)<=?,点击【参数】,在变量栏点击新增以后,把参数的值设置成空,然后在控制流里拖入【sql任务】,怎么来传参数,请老大给出操作过程。测试了好多遍都失败,现在大概就是两种1、取getdate()得到今天时间,再用dateadd来算从今天起要抽取多少天以前的数据, 2、第二种就是从数据库里读取,到时候只要修改数据库里日期就行,请老大给出操作过程,谢谢
第一:ssis有个schedule,在里面就可以直接设置开始时间结束时间,完全不用任何代码
第二:ssis有个控件叫slowly change demension,运用这个控件可以实现你的数据更新判断,超简单