Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a form in which i want to show the data based on user's selection..in this form there is a drop down list with items

'posted','drafted','all'. when user select posted i want to retrieve data by condition Voucher status=true, and when user select drafted i want to retrieve data by condition Voucher status=false. and when user select all i want to retrieve data by condition Voucher status=true or false or null.ie in third display all.(dont want to consider voucher status)

Pls help me to solve this query..

my complete query is here..
SQL
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 or @vtype='0') AND (VoucherHead.VoucherStatus = @st) AND (VoucherHead.Branchno = @branchid) 
GROUP BY VoucherTypes.types, VoucherHead.VoucherNo, VoucherHead.VoucherDate, VoucherHead.VoucherStatus

here
SQL
if (status == 1)
    st = true;

if (status == 2)
   st = false;

where status=drp.selectedindex;

but this works only selecting 'posted' or 'drafted'.. it also be worked when selecting 'all'...

is this can de done using 'case'..i dont know how to use it...pls help me...
Posted
Updated 21-May-15 22:55pm
v2
Comments
Tomas Takac 22-May-15 4:58am    
Ah, I already answered this one... http://www.codeproject.com/Questions/993869/using-case-in-where-clause
Leo Chapiro 22-May-15 5:05am    
Repost from http://www.codeproject.com/Questions/993869/using-case-in-where-clause

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