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
for example, my listbox contains 3 items named 'CTR,DEPO,AISIN'. i make them a string with my loop, my variable
grupkodu is equal to :
'%CTR%' or GRUP_KODU like '%DEPO%' or GRUP_KODU like '%AISIN%'
.
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?