T-SQL 中的“WHERE IN" [英] 'WHERE IN' in T-SQL
本文介绍了T-SQL 中的“WHERE IN"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
参数化 SQL IN 子句?
是否可以使用查询参数来填写IN关键字
我在我的 SQL 查询中使用 WHERE IN,因为用户可能需要输入多个 id 来显示 的记录,用逗号分隔.我现在有这个:
Hi, I'm using WHERE IN in my SQL query as the user may need to enter multiple id's to show records for , seperated by commas. I have this at the moment:
WHERE Consignments.ID IN(@ID)
@ID 是用逗号分隔的 ID 列表.问题是当我的参数有一个数字时它有效 - 如果有多个,那么它不返回任何行.有什么想法吗?
Where @ID will be the list of ID's seperated by commas. Problem is it works when I the parameter has one number - if there's more than one then it returns no rows. Any ideas?
推荐答案
您需要使用动态 sql 或使用带有表变量的存储过程,就像在输入变量中一样.
You need to use dynamic sql or use a stored proc with a table varaiable as in input varaible.
这篇关于T-SQL 中的“WHERE IN"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文