按 charindex >0 和 SQL concat 排序

order by charindex >0 and SQL concat

我想在 ID 在数组中时通过设置优先级来排序 Recordset:

这是逗号分隔的myString,其中包含一系列ID:,1,2,4,6,8,12,34,

我使用 concat 在 ID 前后添加逗号,以便我可以将它与字符串进行比较:

sql="select * from customers order by case when charindex( concat(','," & id & ",',') , '" & myString & "' )>0 then 1 else 0 end desc"

我收到 语法错误 消息。我不确定我在深层结构中使用 concat 时 SQL 结构是否有错误,或者使用引号和双引号时是否有错误?

我在尝试回答@Diado 评论时发现了问题。参数 ID 应该在 SQL 上下文中使用,而不是作为 VbScript 上下文中的变量。所以我将查询更改为此并且有效:

sql="select * from customers order by case when charindex( concat(',',id,',') , '" & myString & "' )>0 then 1 else 0 end desc"