我想从已定义的字符串列表中选择数据,稍后将根据该列表进行基于某些条件的过滤。从字符串列表中选择数据sql
但是,当我想下面的代码:
List<string> inventoryList = new List<string>();
inventoryList.Add("a147");
inventoryList.Add("w150");
string.Format("SELECT * FROM (VALUES '{0}') AS InventoryList(InventoryCode)"
+ " SELECT a.[InventoryCode] FROM [InventoryList] a INNER JOIN [PlayerAccount] b WITH (NOLOCK) ON a.[InventoryCode] = b.[PlayerInventoryCode] WHERE b.[PlayerID] = 146", inventoryList);
--- Other codes to connect to the database and so on ----
它会产生这样的:
SELECT * FROM (VALUES 'System.Collections.Generic.List`1[System.String]') AS InventoryList(InventoryCode) SELECT a.[InventoryCode] FROM [InventoryList] a INNER JOIN [PlayerAccount] b WITH (NOLOCK) ON a.[InventoryCode] = b.[PlayerInventoryCode] WHERE b.[PlayerID] = 146
,而且我得到的错误是:
异常:'System.Collections.Generic.List`1 [System.String]'附近的语法不正确。
编辑:
预期结果将创建InventoryList
表InventoryCode
为列名与内部的上述值:
InventoryList <-- table
InventoryCode <-- column name
1. a147
2. w150
然后,会像普通查询:
SELECT a.[InventoryCode] FROM InventoryList a INNER JOIN [PlayerAccount] ....
您的预期产出是多少? – ekad
而不是你的查询应该如何? –
嗨@ @ usad和@Mohid Shrivastava,查询应该如下所示:'SELECT * FROM(VALUES'a147','w150')AS InventoryList(InventoryCode)''然后,在表'InventoryList'后列名为InventoryCode '有以下数据:'a147'和'w150',然后我将用另一个表格查询结果。谢谢 – Reinhardt