在 Access 2003 SQL 中清理字符串:' 问题

发布于 2024-09-09 06:29:53 字数 535 浏览 3 评论 0原文

我正在编写一个查询,该查询必须计算注册课程的学生人数,我的做法如下:

DCount("[student/course table].[Student ID]","[student/course table]","[StartDate] = #" & [Course Start Date] & "# AND Location = '" & tblCourseDetails.Location & "' AND [Course Number] = '" & [Course Number] & "'")

问题是 Location 可以包含撇号,这会给我的结果带来错误。这似乎搞砸了很多事情(比如它要求我输入参数两次)。有什么简单的方法可以绕过撇号吗?我想也许使用 Replace()=Replace() 这将是一个非常简单的解决方案,但如果还有其他方法可以解决这个问题,我想知道。

我不太担心 SQL 注入。无论如何,要使用此查询,您几乎可以访问数据库。

这不是我的全部问题,如果您认为我应该发布它,请告诉我。

I'm writing a query that has to count the number of students enrolled in a course, and the way I'm doing it is like this:

DCount("[student/course table].[Student ID]","[student/course table]","[StartDate] = #" & [Course Start Date] & "# AND Location = '" & tblCourseDetails.Location & "' AND [Course Number] = '" & [Course Number] & "'")

The problem is that Location can contain apostrophes, which throws errors into my results. This seems to screw up a lot of things (like it asks for me to enter a parameter twice). Is there any simple way to get around apostrophes? I was thinking maybe using Replace()=Replace() which would be a pretty simple solution, but if there's any other ways around this I'd like to know.

I'm not too worried about SQL injection. To use this query you'd have pretty much access to the database anyways.

This isn't my whole query, if you think I should post it, tell me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静若繁花 2024-09-16 06:29:53

您需要添加转义字符。对于访问,我相信它是“”。

因此,找到 ' 并将其替换为 '' 就可以了。

编辑:这是一个额外的撇号,而不是双引号。

Replace(tblCourseDetails.Location, "'", "''")

You need to add an escape character. For access I believe it is '' for '.

So find and replace ' with '' and you should be good to go.

Edit: That is an extra apostrophe, not a double quotation mark.

Replace(tblCourseDetails.Location, "'", "''")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文