如何根据 varchar 列上基于数字的 RANGE 过滤器选择行?
如果我有一个长度为 30 的 varchar 列:
[SpecificCode] --> varchar(30) 在名为 [Item] 的数据库表中
如果我必须查询此表行以获取
SpecificCode 在 789 到 15000 之间
的所有行可能是什么在 TSQL 中进行 SELECT 的最快方法是什么? (长度为30的varchar字段需要进行范围测试)
SELECT *
FROM Item
WHERE Item.SepecificCode --how to filter between 789 and 15000?
If I have a varchar column which has the length 30:
[SpecificCode] --> varchar(30) in a db table called [Item]
And if I have to query this table rows to obtain all the rows which have
SpecificCode between 789 and 15000
What may be the fastest way to SELECT in TSQL? (Range test is needed on a varchar field with length 30)
SELECT *
FROM Item
WHERE Item.SepecificCode --how to filter between 789 and 15000?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设该列充满非数字垃圾但没有小数
如果只是整数
如果也浮动:
Assuming the column is full of non-numeric rubbish but no decimals
If just integers
If floats too:
它会是这样的:
但为了提高性能,您应该在 SepecificCode 列中创建一个
索引
。It would be something like this:
but to improve performance you should create a
index
in the SepecificCode column.尝试强制 sql 将列作为 INT 读取
,据我所知,该列上的任何索引都是无用的,因为它们是为 varchar 数据而不是整数创建的,请尝试使用以下命令查看:
Try forcing sql to read the column as a INT
AFAIK any index you have on that column is usless, beacause they are created for varchar data not integers, try see that with: