日期:2014-05-18  浏览次数:20538 次

case 嵌套正确写法问题
declare   @type   as   int
declare   @id   as   int
set   @type=3
set   @id=1
SELECT      
            CASE  
                  WHEN   @type   in(1,4,6)   THEN  
select  
case  
when   @id   in(1)   then   'A '
when   @id   in(2)   then   'a '
end
                  WHEN   @type   in(2,5)   THEN  
select  
case  
when   @id   in(1)   then   'B '
when   @id   in(2)   then   'b '
end
                  WHEN   @type   in(3)   THEN   'C '
            END


------解决方案--------------------
SELECT
CASE
WHEN @type in(1,4,6) THEN
case
when @id in(1) then 'A '
when @id in(2) then 'a '
end
WHEN @type in(2,5) THEN
case
when @id in(1) then 'B '
when @id in(2) then 'b '
end
WHEN @type in(3) THEN 'C '
END

------解决方案--------------------
declare @type as int
declare @id as int
set @type=3
set @id=1
SELECT
CASE
WHEN @type in(1,4,6) THEN
--select
case
when @id in(1) then 'A '
when @id in(2) then 'a '
end
WHEN @type in(2,5) THEN
--select
case
when @id in(1) then 'B '
when @id in(2) then 'b '
end
WHEN @type in(3) THEN 'C '
END