在where语句参数中的情况

时间:2011-06-13 03:04:03

标签: sql sql-server sql-server-2005

select docket_number,aging from (
    select docket_number, 
        sum(cast(dateDiff("mi",assigned,coalesce(completed,getdate()))/60.00 as decimal(20,2))) aging

    from ft_details_h 

    group by docket_number
)a where aging case  when  @hh <= 72 then  <= @hh else  > @hh end

大家好,我怎么能在参数@hh小于或= 72时满足where语句where语句应该老化&lt; = @hh当老化大于72时where语句应该老化&gt ; @hh

2 个答案:

答案 0 :(得分:0)

你可以这样做:

where 
    (@hh <= 72 and aging <= @hh) or
    (@hh > 72 and aging > @hh)

答案 1 :(得分:0)

在撰写问题时,请尝试:

   where (aging <= @hh And @hh <= 72) Or 
         (aging > @hh And aging > 72)

但我怀疑你有一个拼写错误,实际上意味着

   where (aging <= @hh And @hh <= 72) Or 
         (aging > @hh  And @hh > 72)