我有一個查詢,其中提供了逗號分隔的條形碼。但不知什麼原因,它是不工作:SQL服務器,SQL查詢,「IN」語句不起作用
下面是不起作用
DECLARE @txtBarcode VARCHAR(MAX)
SET @txtBarcode = '2003824,2003825';
SELECT [Scan_Curr_Location]
FROM BarCode_Location_Current
WHERE Scan_Curr_BarCodeNo IN (@txtBarcode)
ORDER BY [Scan_Curr_BarCodeNo] ASC
然而,當我將其更改爲一個單一的條形碼它工作正常,即代碼:
SET @txtBarcode = '2003824';
請指教。
謝謝!
請參閱此處接受的答案:https://stackoverflow.com/questions/3516064/creating-a-sql-table-from-a-comma-concatenated-list 。我一直很喜歡解決這個問題的方式。 – VBlades