如何使用or语句将多个变量传递给存储过程 [英] How to pass multiple variable to stored procedure with or statement
本文介绍了如何使用or语句将多个变量传递给存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表框包含一些品牌的产品。我使它们成为一个带有for循环的字符串,如:
i have a listbox contains some brand names of products. i make them a string with a for loop like :
string kod;
string grupkodu;
for (int i = 0; i < listBox2.Items.Count; i++)
{
grupkodu = grupkodu + kod + "'%" + listBox1.Items[i].ToString() + "%'";
kod = "or GRUP_KODU LIKE ";
}
我的存储过程是:
and my stored procedure is :
ALTER PROC [dbo].[AHMETILKKARTHAREKETGETIR]
(
@CARIKOD VARCHAR(10),
@BASTARIH DATETIME,
@BITTARIH DATETIME,
@GRUPKOD VARCHAR(999)
)
AS
BEGIN
SELECT STHAR_TARIH AS 'TARIH',FISNO AS 'FATURA NO',TBLSTSABIT.STOK_KODU AS 'STOK KODU',TBLSTSABIT.URETICI_KODU AS 'URETICI KODU',STHAR_GCMIK AS 'ADET'
FROM TBLSTSABIT LEFT OUTER JOIN TBLSTHAR ON TBLSTSABIT.STOK_KODU = TBLSTHAR.STOK_KODU
WHERE STHAR_ACIKLAMA =@CARIKOD AND STHAR_TARIH>=@BASTARIH AND STHAR_TARIH<=@BITTARIH AND
(GRUP_KODU LIKE @GRUPKOD )
ORDER BY STHAR_TARIH,FISNO,URETICI_KODU
END
例如,我的列表框包含3个名为CTR,DEPO,AISIN的项目。我用循环使它们成为一个字符串,我的变量 grupkodu 等于:
'%CTR%' or GRUP_KODU like '%DEPO%' or GRUP_KODU like '%AISIN%'
。
i尝试传递我的存储过程的@GRUPKOD变量此字符串并尝试从我的数据库中选择多行。但是我这样做时出错了。我不知道为什么。
我怎么能用sql存储过程发送多个变量或者声明?这样做的正确方法是什么?
.
i try to pass the @GRUPKOD variable of my stored procedure this string and try to select multiple rows from my database. but i got an error while doing this. i dont know why.
how can i send multiple variables with or statement to sql stored procedure? what is the right way to do this?
推荐答案
嗨朋友,
查看以下链接。 ...
如果您使用的是SQL Server 2008或者预付款,那么您可以使用用户定义类型...
将数据表发送到存储过程 [ ^ ]
问候,
GVPrabu
Hi Friend,
Check the following link....
If u are using SQL server 2008 or advance then u can use User Define Type for this...
Sending a DataTable to a Stored Procedure[^]
Regards,
GVPrabu
这篇关于如何使用or语句将多个变量传递给存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文