declare @timm varchar(2)
select @timm=cast(datepart(hh,getdate()) as varchar(2))select * from
(
select c.pihao,c.sxrq,c.shl as kcsl,a.jwh,
case xshy when @timm in ('08','09','10','11','12','13') then select xshy from xshydoc where xshyid like  '%A%' else select xshy from xshydoc where xshyid like '%P%' end 
 from hwsp a,sphwph c
where a.spid=c.spid and a.spbh like '1101615')b
order by b.kcsl desc

解决方案 »

  1.   

    THEN后的SQL语句只能返回单一字段,什么问题?
      

  2.   

    数据库结构
    A001   张三
    A002   李四
    P001   王五
    P002   赵六
    上午选择A下午选择B
    就是这样.怎么用SQL_T办到?
      

  3.   

    难到用top 1 xshy也不行吗?
      

  4.   

    你是在MYSQL下?MYSQL没有OPT,用LIMIT代替
      

  5.   

    哦。我是在MSSQL—T下用select top 1 xshy from xshydoc
    不能用在CASE里取的第一条记录第一个字段啊