sql - 按 charindex >0 和 SQL concat 排序
问题描述
当 ID 在数组中时,我想通过设置优先级来订购 Recordset:
这是包含一系列 ID的逗号分隔的myString :,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"
推荐阅读
- php - 货运现场的功能表格?
- python - 从 Pandas 列中分解 dict
- amazon-cognito - Cognito:了解 LimitExceededException
- angular - 本地存储中的 Angular 缓存 http
- xquery - 如何操作文件路径
- wordpress - woocommerce_process_shop_order_meta 挂钩中的客户 ID 为 0
- javascript - 如何在 ios webview 中隐藏输入蓝色插入符号?
- c - PIC18F 上的定时器 0 中断
- javascript - 如何向 Google pagespeed API 发送批量请求?
- node.js - Next.js 受限页面和用户认证最佳实践