读书人

case 嵌套正确写法有关问题

发布时间: 2012-03-27 13:44:24 作者: rapoo

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

读书人网 >SQL Server

热点推荐