动态SQL Server查询 [英] Dynamic SQL Server query
本文介绍了动态SQL Server查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有两张桌子RCP(收据,反对,付款)和JDC(Journal,DebitNote,CreditNote)。
和i存储RCP中的交易类型((收据= 1,Contra = 2,Payment = 3)和
(Journal = 4,DebitNote = 6,CreditNote = 7)在JDC中一些专栏。
现在我如何编写查询以从表中检索数据,如果我发送的字符串参数由逗号分隔的类型组成。
Ex:1,2,3,4,5,6
2,4,5
1,2,3,6
3,4,5,6
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
推荐答案
尝试这样的事情:
Hi,
Try something like this :
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,
检查以下链接
如何在sql中编写动态查询 [ ^ ]
SQL查询的效率 [ ^ ]
问候,
GVPrabu
Hi,
Check the following links
how to write a dynamic query in sql[^]
efficiency of the SQL query[^]
Regards,
GVPrabu
这篇关于动态SQL Server查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文