如何在mysql和vb.net中使用带IN运算符的parameters命令
我需要在WHERE子句中使用IN运算符,因此我尝试使用SQL语句编写下一段代码,但它只提供了第一个数字的记录:如何在mysql和vb.net中使用带IN运算符的parameters命令,mysql,sql,string,vb.net,where-clause,Mysql,Sql,String,Vb.net,Where Clause,我需要在WHERE子句中使用IN运算符,因此我尝试使用SQL语句编写下一段代码,但它只提供了第一个数字的记录: MyVar_AccID= "110,112,113" Dim MyVar_SqlStr_Main As String = "SELECT FatoraID, FatoraRef,
MyVar_AccID= "110,112,113"
Dim MyVar_SqlStr_Main As String = "SELECT
FatoraID,
FatoraRef,
FatoraCode,
FatoraDate,
(D.AccName) AS DName,
FatoraQuan,
CONCAT(CategoryName,' ',ProductName) AS ProdName,
FatoraSalePrice,
(C.AccName) AS CusName,
FatoraPurPrice,
(R.AccName) AS ResoName,
FatoraPalletQuan,
FatoraPalletPrice,
FatoraPurTotal,
FatoraCustomer,
FatoraDis,
FatoraPlus,
FatoraSaleTotal,
FatoraDriver,
FatoraCarNo,
FatoraDriverCost,
FatoraDriverCostTotal1,
FatoraDriverCostTotal2,
FatoraDriverPrice,
FatoraDriverPayStatus,
FatoraReso,
FatoraProduct,
FatoraDetails1,
FatoraDetails2,
FatoraDetails3,
(FatoraPalletQuan * FatoraPalletPrice) AS PalletTotalPrice
FROM tblfatora F
INNER JOIN tblproducts P ON
P.ProductID = F.FatoraProduct
INNER JOIN tblaccounts R ON
R.AccID = F.FatoraReso
INNER JOIN tblaccounts C ON
C.AccID = F.FatoraCustomer
LEFT JOIN tblaccounts D ON
D.AccID = F.FatoraDriver
INNER JOIN tblcategories CT ON
CT.CategoryID = P.ProductCategory
Where
(FatoraReso IN (@FatoraReso))
ORDER BY FatoraDate DESC"
xCmd = New MySqlCommand(MyVar_SqlStr_Main, Conn)
xCmd.Parameters.Add("@FatoraReso", MySqlDbType.VarChar).Value = MyVar_AccID
我也试过:
Where
(FatoraReso IN ("@FatoraReso"))
但是没有给我结果,我如何解决这个问题,请注意,我不知道代码的数量,所以可能会是(1,2,3,4,5)或更少或更多。您似乎想检查一个值是否属于逗号分隔的列表。您不能使用中的
,它需要一个值列表,而不是一个值字符串
通用解决方案使用字符串函数:
where concat(',', @fatorareso, ',') like concat('%,', fatorareso, ',%')
但是,在MySQL中,您可以使用:
很好,非常感谢。请注意,这将使查询无法在fatora上使用索引。问题是,参数化的“IN”子句不能接受多个值。这里有一个解决方法:
where find_in_set(fatorareso, @fatorareso)