Click here to Skip to main content
16,004,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have two tables RCP(Receipt,Contra,Payment) and JDC(Journal,DebitNote,CreditNote).
And i store type of transaction ((Receipt=1,Contra=2,Payment=3) in RCP and
(Journal=4,DebitNote=6,CreditNote=7) in JDC ) in some column.

Now how do i write the query to retrieve data from tables if i send string parameter consisting of types seperated by comma.
Ex: 1,2,3,4,5,6
2,4,5
1,2,3,6
3,4,5,6
Posted
Comments
Vimal Raj 22-Apr-13 6:36am    
Could you please make it more clear. Include sample input and expected output. Do you want to filter the results based on transaction type being any of the comma seperated values. Do you need to join/union the two tables.
gvprabu 22-Apr-13 9:46am    
See Use Dynamic Query Concepts...

Hi,
Try something like this :
SQL
select * from
(select code,voucherNo,Amt,Type from RCP
union
select code,voucherNo,Amt,Type from JDC)a
where a.type in(1,2,3,4,5)


Thanks,
 
Share this answer
 
Comments
DileepkumarReddy 22-Apr-13 7:48am    
Thank you very much !!!
Member 7686563 22-Apr-13 7:55am    
Most welcome
StianSandberg 22-Apr-13 17:28pm    
Perfect.. 5'd
Hi,
Check the following links
how to write a dynamic query in sql[^]
efficiency of the SQL query[^]
Regards,
GVPrabu
 
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