问题时的SQL查询 [英] SQL Query when Problem

查看:64
本文介绍了问题时的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

This following query arises error and the error is :
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'when'."


SELECT  case  when count(VCode)as [Todays Approval]='' then 0 else [Todays Approval] end , ApprovedDate, StateStatus, TRDate
FROM         tblTransactionInformation
WHERE     VCode = 'VCH-004' AND approvedDate = '30-Sep-2013'  AND JournalName = 'Bank Receive Voucher'
GROUP BY ApprovedDate, StateStatus, TRDate
Please help me

推荐答案

您好,



这将解决您的问题..



选择

案例

当计数(VCode)=''然后0

否则[今日批准]

结束

as TodaysApproval

,ApprovedDate,StateStatus,TRDate

FROM tblTransactionInformation

WHERE VCode ='VCH-004'AndifiedDate = '30 -Sep-2013'JournalName ='银行领取凭证'

GROUP BY ApprovedDate,StateStatus,TRDate



如果解决了,请不要忘记将其标记为答案你的问题。



问候,

Mubin
Hi ,

This will solve your problem..

select
case
when count(VCode)='' then 0
Else [Todays Approval]
end
as TodaysApproval
, ApprovedDate, StateStatus, TRDate
FROM tblTransactionInformation
WHERE VCode = 'VCH-004' AND approvedDate = '30-Sep-2013' JournalName = 'Bank Receive Voucher'
GROUP BY ApprovedDate, StateStatus, TRDate

Do not forget it to mark as answer if it resolve your issue.

Regards,
Mubin


SELECT  case count(VCode) when 0 then NULL else [Todays Approval] end as [Todays Approval] , ApprovedDate, StateStatus, TRDate
FROM         tblTransactionInformation
WHERE     VCode = 'VCH-004' AND approvedDate = '30-Sep-2013'  AND JournalName = 'Bank Receive Voucher'
GROUP BY ApprovedDate, StateStatus, TRDate


请试试这个



Please try this one

SELECT
    ApprovedDate, StateStatus, TRDate,
    ISNULL(count(VCode), 0)[Todays Approval]
FROM  tblTransactionInformation
WHERE VCode = 'VCH-004'
      AND approvedDate = '30-Sep-2013'
      AND JournalName = 'Bank Receive Voucher'
GROUP BY ApprovedDate, StateStatus, TRDate


这篇关于问题时的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆