• 通过where 作为swith的条件


    ALTER PROCEDURE [Common].[usp_Upload_ReturnOrganizationData]
    @moduleID INT,
    @EffectiveYear CHAR(4)
    AS 
    
    SELECT distinct EffectiveFrom
    ,EffectiveTo
    ,OrgUnit
    ,LevelNo
    ,ShortDescription
    ,LongDescription 
    INTO #Temp
    FROM 
    (select * from CBPFR.tblOrganization where @moduleID=1 
     UNION ALL SELECT * FROM ShopAccount.tblOrganization WHERE @moduleID=2
     UNION ALL SELECT * FROM BMR.tblOrganization WHERE @moduleID=5
    ) Tab
    WHERE Tab.EffectiveYear=@EffectiveYear
    
    
    
    SELECT 
    		EffectiveFrom
    		,EffectiveTo
    		,OrgLevel1
    		,OrgLevel2
    		,OrgLevel3
    		,OrgLevel4
    		,OrgLevel5
    		,OrgLevel6
    		,OrgLevel7
    		,OrgLevel8
    		,OrgLevel9
    		,OrgLevel10
    		,L1LongDescription=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel1=OrgUnit AND LevelNo=1 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L1ShortDescription=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel1=OrgUnit AND LevelNo=1 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L2LongDescription=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel2=OrgUnit AND LevelNo=2 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)	
    		,L2ShortDescription	=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel2=OrgUnit AND LevelNo=2 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L3LongDescription	=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel3=OrgUnit AND LevelNo=3 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L3ShortDescription=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel3=OrgUnit AND LevelNo=3 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L4LongDescription=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel4=OrgUnit AND LevelNo=4 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L4ShortDescription=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel4=OrgUnit AND LevelNo=4 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L5LongDescription=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel5=OrgUnit AND LevelNo=5 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L5ShortDescription	=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel5=OrgUnit AND LevelNo=5 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L6LongDescription	=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel6=OrgUnit AND LevelNo=6 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L6ShortDescription	=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel6=OrgUnit AND LevelNo=6 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L7LongDescription	=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel7=OrgUnit AND LevelNo=7 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L7ShortDescription	=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel7=OrgUnit AND LevelNo=7 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L8LongDescription	=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel8=OrgUnit AND LevelNo=8 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L8ShortDescription	=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel8=OrgUnit AND LevelNo=8 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L9LongDescription	=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel9=OrgUnit AND LevelNo=9 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L9ShortDescription	=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel9=OrgUnit AND LevelNo=9 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L10LongDescription	=(SELECT TOP 1 LongDescription FROM #Temp T WHERE OrgLevel10=OrgUnit AND LevelNo=10 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    		,L10ShortDescription=(SELECT TOP 1 ShortDescription FROM #Temp T WHERE OrgLevel10=OrgUnit AND LevelNo=10 AND Org.EffectiveFrom=T.EffectiveFrom AND Org.EffectiveTo=T.EffectiveTo)
    FROM
    (select * from CBPFR.tblOrganization where @moduleID=1 
     UNION ALL SELECT * FROM ShopAccount.tblOrganization WHERE @moduleID=2
     UNION ALL SELECT * FROM BMR.tblOrganization WHERE @moduleID=5
    )  Org
    WHERE Org.IsOriginalRecord=1
    AND Org.EffectiveYear=@EffectiveYear
    
    
    
    先判断where语句 ,然后在select
  • 相关阅读:
    java数组
    python中的换行与不换行
    金融业务知识2---资金的时间价值与跨时期优化
    金融业务知识1---金融和金融系统
    你真的理解正向代理和反向代理吗?
    webpack(9)plugin插件功能的使用
    webpack(8)vue组件化开发的演变过程
    webpack(7)webpack使用vue配置
    webpack(6)webpack处理图片
    webpack(5)webpack处理css文件
  • 原文地址:https://www.cnblogs.com/flysun0311/p/1742878.html
Copyright © 2020-2023  润新知