比较SQL语句中的日期

时间:2015-12-24 11:46:39

标签: sql-server select

我尝试使用以下语句来检查订单是否延迟,但会导致语法错误。我怎么写呢?

select (enddate > targetdate ) as late from orders

2 个答案:

答案 0 :(得分:4)

您似乎正在搜索与case表达式类似的内容:

select 
    case 
        when enddate > targetdate then 1 
        else 0 
    end as late
from orders

答案 1 :(得分:1)

我想你需要case

select 
    case 
        when enddate > targetdate then 'enddate  is greater' 
        else 'targetdate is greater' 
    end as late
from orders