日期:2014-05-16 浏览次数:20444 次
if object_id('tempdb..#a') is not null
drop table #a
create table #a(Id int,Name nvarchar(5),Show_Order int)
insert into #a select 1,'A',4 union all select 2,'B',5 union all select 3,'C',6
DECLARE @a INT =6
DECLARE @Max INT
DECLARE @Min INT
select @max=MAX(Show_Order),@Min=MIN(Show_Order)
from #a
IF (SELECT Show_Order FROM #a WHERE Show_Order=@a)=@Max
BEGIN
SELECT 3
END
ELSE IF (SELECT Show_Order FROM #a WHERE Show_Order=@a)=@min
BEGIN
SELECT 1
END
ELSE
BEGIN
SELECT 2
END
select id, CASE Show_Order
WHEN (select max(Show_Order) from #a) THEN 'MAX'
WHEN (select min(Show_Order) from #a) THEN 'MIN'
ELSE 'OTHER'
END
from #a
where Show_Order = @Show_Order