select top 1 a.*,b.CheckName,b.Tel,(select datediff(d,getdate(),c.Coupon_End)<0) as isExpired 
from CouponInfo a 
inner join OrderInfo b on a.OrderNum=b.OrderNum
inner join Products c on a.ProductID=c.ProductID 
where CouponCode=@CouponCode错误:'<' 附近有语法错误。
,(select datediff(d,getdate(),c.Coupon_End)<0) as isExpired 这样写不对,要如何写?

解决方案 »

  1.   

    select top 1 a.*,b.CheckName,b.Tel,case when datediff(d,getdate(),c.Coupon_End)<0 then 1 else 0 end as isExpired 
                from CouponInfo a 
                    inner join OrderInfo b on a.OrderNum=b.OrderNum
                    inner join Products c on a.ProductID=c.ProductID 
                where CouponCode=@CouponCode
      

  2.   

    select top 1 a.*,b.CheckName,b.Tel, datediff(d,getdate(),c.Coupon_End)<0 as isExpired 
                from CouponInfo a 
                    inner join OrderInfo b on a.OrderNum=b.OrderNum
                    inner join Products c on a.ProductID=c.ProductID 
                where CouponCode=@CouponCode无须那个select
      

  3.   

    写成
    datediff(d,getdate(),c.Coupon_End)<0 as isExpired 
    (datediff(d,getdate(),c.Coupon_End)<0) as isExpired 
    都错,我晕死·!
      

  4.   

    select top 1 a.*,b.CheckName,b.Tel,
    CASE WHEN datediff(d,getdate(),c.Coupon_End)<0 THEN '过期' 
     WHEN datediff(d,getdate(),c.Coupon_End)>0 THEN '没过期'  end
    as isExpired 
                from CouponInfo a 
                    inner join OrderInfo b on a.OrderNum=b.OrderNum
                    inner join Products c on a.ProductID=c.ProductID 
                where CouponCode=@CouponCode