本文介绍了在where子句中使用case的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码..但它有一些错误...请帮助我

I have used following code.. but it have some erors...pls help me

SELECT        VoucherTypes.types, VoucherHead.VoucherNo, VoucherHead.VoucherDate, SUM(VoucherDetail.Debit) AS debit, SUM(VoucherDetail.Credit) AS credit,
                         VoucherHead.VoucherStatus
FROM  VoucherHead INNER JOIN VoucherTypes ON VoucherHead.VoucherType = VoucherTypes.vtypeid INNER JOIN
                         VoucherDetail ON VoucherHead.VoucherID = VoucherDetail.VoucherID
WHERE        (VoucherHead.VoucherDate >= @fromdate) AND (VoucherHead.VoucherDate <= @todate) AND (VoucherTypes.types = @vtype) AND (VoucherHead.Branchno = @branchid)and case(VoucherHead.VoucherStatus)when @val=1 then VoucherHead.VoucherStatus='true' when @val=2 then VoucherHead.VoucherStatus=false when @val=0 then VoucherHead.VoucherStatus=true or VoucherHead.VoucherStatus=false or VoucherHead.VoucherStatus is null

GROUP BY VoucherTypes.types, VoucherHead.VoucherNo, VoucherHead.VoucherDate, VoucherHead.VoucherStatus





请帮助我纠正这个...



pls help me to correct this...

推荐答案

CASE column_name
WHEN condition1 THEN result1
WHEN condition2 THEN result2
  ...
ELSE result
END





我不喜欢在查询中找不到任何 END


WHERE
...
    AND (
        @val = 3
        OR (@val = 2 AND VoucherHead.VoucherStatus='false')
        OR (@val = 1 AND VoucherHead.VoucherStatus='true')
    )


这篇关于在where子句中使用case的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 07:09
查看更多