我有一個名爲itemIDs的逗號分隔的字符串(12,43,34,..),並且爲了將它用作參數,我需要將它轉換爲int,因爲db中的itemID是以int格式。在sql查詢中使用charindex
這是我寫的,但我得到一個錯誤說Incorrect syntax near the keyword 'as'.
using (SqlCommand searchResult = new SqlCommand("SELECT ItemID, Name, RelDate, Price, Status FROM item_k WHERE (itemID = cast(charindex(',',(@itemIDs as int))))", searchCon))
我無法弄清楚,什麼似乎是這裏的問題?