Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"
XML
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
Posted
Updated 5-Oct-13 19:41pm
v8

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
 
Share this answer
 
v2
Comments
Sumon562 6-Oct-13 1:56am    
Now it shows the following error :
Msg 207, Level 16, State 1, Line 4
Invalid column name 'Todays Approval'.
SQL
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
 
Share this answer
 
Please try this one

SQL
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
 
Share this answer
 
SQL
SELECT  case  when count(VCode)='' then 0 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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900