create table t_1(ID int, MID int, Date datetime)insert t_1 select 1, NULL, '2007-1-21'insert t_1 select 2, NULL, '2007-3-25'insert t_1 select 3, NULL, '2007-3-26'create table t_2(ID int, Date datetime)insert t_2 select 1, '2007-1-22'insert t_2 select 2, '2007-1-25'insert t_2 select 3, '2007-1-29'update a set mid=b.idfrom t_1 aleft join t_2 bon b.date=(select max(date) from t_2 xwhere date<=a.dateand not exists(select 1 from t_1 ywhere id<a.id and date>=x.dateand not exists(select 1 from t_2 where date>x.date and date<=y.date)))--orupdate a set mid=b.idfrom t_1 aleft join t_2 bon b.date=(select max(date) from t_2 xwhere date <=a.dateand (select count(*) from t_2 where date>=x.date and date<=a.date)=(select count(*) from t_1 where id<a.id and date>=x.date)+1)drop table t_1,t_2
select a.*,cnt = (select count(*) from tb where group_id= a.group_id) from ta a
select a.*,isnull(b.cnt,0) from ta a,left join (select group_id,count(*) from tb group by group_id) bon a.group_id = b.group_id
select distinct b.sku_no, b.vend_nointo #skufrom part b, inv_qty awhere a.sku_no = b.sku_noand a.inv_type = 300
create table #sku(sku_no int null, vend_no int null)insert #sku(sku_no) select distinct sku_no from inv_qty where inv_type =300exec('create index idx1 on #sku(sku_no)')exec('update #sku set vend_no = b.vend_no from #sku a,part b where a.sku_no = b.sku_no')delete from #sku where vend_no is null
create table #sku(sku_no int null, vend_no int null)insert #sku(sku_no) select distinct sku_no from inv_qty where inv_type =300create index idx1 on #sku(sku_no)update #sku set vend_no = b.vend_no from #sku a,part b where a.sku_no = b.sku_nodelete from #sku where vend_no is null
update #ordersset cust_no = b.cust_nofrom #orders a,Cur..history_header bwhere a.order_no = b.order_noand a.order_type = b.order_type
set rowcount 10000select @@rowcountwhile @@rowcount>0update #ordersset cust_no = b.cust_nofrom #orders a,Cur..history_header bwhere a.order_no = b.order_noand a.order_type = b.order_typeand a.cust_no is nulland b.cust_no is not nullset rowcount 0
联系客服