国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

兩則實現相同功能的代碼比較(使用臨時表與不用臨時表比較)

2024-07-21 02:11:56
字體:
來源:轉載
供稿:網友

if (not exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[old_outid]') and objectproperty(id, n'isusertable') = 1))
begin
 select customerid,outid into old_outid from t_customers
 --update  t_customers set outid='請輸入新的學工號'
/* --把新工號恢復成老工號值
update t_customers
set t_customers.outid = old_outid.outid
from old_outid
where old_outid.customerid = t_customers.customerid
*/
end


select *  into #dpt from (select  dpcode1+dpcode2+dpcode3 as 部門代碼,dpname1+'/'+dpname2+'/'+dpname3 as 部門名稱  from t_department where dpname1 is not null and dpname2 is not null and dpname3 is not null union all select dpcode1+dpcode2+dpcode3 as 部門代碼,dpname1+'/'+dpname2 as 部門名稱 from t_department where dpname1 is not null and dpname2 is not null and dpname3 is  null union all select  dpcode1+dpcode2+dpcode3 as 部門代碼,dpname1 as 部門名稱 from t_department where dpname1 is not null and dpname2 is  null and dpname3 is  null) l


select customerid, max(opdt) as 最近一次補卡時間 into #renewcard_maxdt
from t_renewcard
group by customerid


select 部門名稱,name as 姓名, alias as 別名, cardtype as 卡類, c.outid as 新工號,o.outid as 舊工號,最近一次補卡時間
from t_customers c inner join #dpt d on d.部門代碼=c.account inner join #renewcard_maxdt r on
r.customerid=c.customerid inner join old_outid o on c.customerid=o.customerid
where (c.cardtype in (1, 2))

drop table #dpt
drop table #renewcard_maxdt


/* --作視圖代碼,功能同上,不便閱讀理解與修改更新,但適用廣。
select d.部門名稱, c.name as 姓名, c.alias as 別名, c.cardtype as 卡類,
      c.outid as 新工號, o.outid as 舊工號, r.最近一次補卡時間
from t_customers c inner join
          (select dpcode1 + dpcode2 + dpcode3 as 部門代碼,
               dpname1 + '/' + dpname2 + '/' + dpname3 as 部門名稱
         from t_department
         where dpname1 is not null and dpname2 is not null and
               dpname3 is not null
         union all
         select dpcode1 + dpcode2 + dpcode3 as 部門代碼,
               dpname1 + '/' + dpname2 as 部門名稱
         from t_department
         where dpname1 is not null and dpname2 is not null and
               dpname3 is null
         union all
         select dpcode1 + dpcode2 + dpcode3 as 部門代碼, dpname1 as 部門名稱
         from t_department
         where dpname1 is not null and dpname2 is null and dpname3 is null)
      d on d.部門代碼 = c.account inner join
          (select customerid, max(opdt) as 最近一次補卡時間
         from t_renewcard
         group by customerid) r on r.customerid = c.customerid inner join
      old_outid o on c.customerid = o.customerid
where (c.cardtype in (1, 2))
*/

國內最大的酷站演示中心!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 寿阳县| 贵德县| 濉溪县| 汉源县| 文山县| 新余市| 富锦市| 丹凤县| 扬州市| 秦安县| 繁昌县| 新蔡县| 玉山县| 云龙县| 曲周县| 宿州市| 平谷区| 奇台县| 宝兴县| 新巴尔虎左旗| 呼伦贝尔市| 二连浩特市| 江都市| 岚皋县| 汽车| 迁西县| 綦江县| 灵丘县| 微山县| 双桥区| 牟定县| 东山县| 宿松县| 金秀| 中西区| 宁津县| 高雄县| 延安市| 犍为县| 星子县| 兴国县|