SQL Select 语句不会返回字符字段,仅返回数字字段
我今天一整天都在为这个问题绞尽脑汁。 我有以下 ASP 代码,它使用下拉框中的 Request.Querystring 输入 启动 select 语句。 querystrinch 确实显示在 ?= URL 中,但仅适用于 Microsoft SQL DB 中的数字列。我无法查找名称或简单的 3 个字符字段。
CODE:
If Request.QueryString("m") > 0 Then
filterID = Request.QueryString("m")
filterColmn = "imDegree"
Else filterID = 0
End If
If filterID > 0 Then
SQlQuery = "SELECT * FROM v_InternImport WHERE iID IN (SELECT iID FROM v_InternImport WHERE " & filterColmn & " = " & filterID & ")"
End If
End If
我知道这个选择语句作为其中的子选择语句,但我什至无法从我的数据库中获得直接返回。 select 语句引用了填充之前加载的主 asp 页面的相同视图,并且显示正常?
I have been racking my brain over this all day today.
I have the following ASP code that uses a Request.Querystring input from a dropdown box
to launch a select statement. The querystrinch does show in the ?= URL but will only work on
columns in the Microsoft SQL DB that are numeric. I cant lookup names or simple 3 character fields.
CODE:
If Request.QueryString("m") > 0 Then
filterID = Request.QueryString("m")
filterColmn = "imDegree"
Else filterID = 0
End If
If filterID > 0 Then
SQlQuery = "SELECT * FROM v_InternImport WHERE iID IN (SELECT iID FROM v_InternImport WHERE " & filterColmn & " = " & filterID & ")"
End If
End If
I understand that this select statement as a sub select stament in it but I cant even get a staight reuturn from my DB. The select statement references the same view that populates the main asp page that loads before and the shows fine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将字符串传递到 SQL Server 时,需要用单引号将其引起来。
当您传递数字时,不使用引号。
因此,当您说(总结)
SELECT * FROM table WHERE filterColumn = filterID
时,您应该发送一个数字。
匹配字符串:
SELECT * FROM table WHERE filterColumn = 'filterID'
这假设您已经解决了评论者提到的有关
filterID
变量中是否有值的任何其他问题。我衷心同意使用参数化查询的建议。编辑:单引号放在双引号内。
When you pass a string to SQL Server, you need to surround it with single quotes.
When you pass a number, you don't use the quotes.
So, when you say (summarizing)
SELECT * FROM table WHERE filterColumn = filterID
you should be sending a number.
To match a string:
SELECT * FROM table WHERE filterColumn = 'filterID'
This assumes that you have solved any other problems mentioned by the commenters about whether you even have a value in the
filterID
variable. I heartly concur with the recommendation to use parameterized queries.Edit: The single quotes go inside the double quotes.