如何过滤 SQL Server 数据库查询中的值?

发布于 2024-12-03 18:58:03 字数 769 浏览 2 评论 0原文

我有一个针对 MySQL 数据库运行良好的查询,但我们必须将数据库和应用程序迁移到 SQL Server。现在我在让这个查询工作时遇到了麻烦。

SELECT  
   complist.CompName, 
   complist.CompID, 
   componenttrace.Remark, 
   complist.McID, 
   complist.Station, 
   complist.Slot, 
   complist.Amount - complist.Used - ISNULL(complist.Correction,0) 
FROM 
   complist, componenttrace 
WHERE 
   complist.McID = 1004 
   AND complist.CompID = componenttrace.CompID 
   AND UPPER(complist.Station + '.' + complist.Slot) LIKE '%1.1%'
ORDER BY 
   complist.CompName, complist.CompID

该部分

AND UPPER(complist.Station + '.' + complist.Slot) LIKE '%1.1%'

在应用程序上,如果给定字段(即 1.1)上有任何值,则会自动添加

。我有 SQL 语法问题,但不知道如何解决。任何人都可以在这里阐明一些情况吗?

谢谢,

古斯塔沃

I've a query that works OK against a MySQL database, but we've had to migrate the database and applications to SQL Server. Now I'm in trouble getting this query to work.

SELECT  
   complist.CompName, 
   complist.CompID, 
   componenttrace.Remark, 
   complist.McID, 
   complist.Station, 
   complist.Slot, 
   complist.Amount - complist.Used - ISNULL(complist.Correction,0) 
FROM 
   complist, componenttrace 
WHERE 
   complist.McID = 1004 
   AND complist.CompID = componenttrace.CompID 
   AND UPPER(complist.Station + '.' + complist.Slot) LIKE '%1.1%'
ORDER BY 
   complist.CompName, complist.CompID

On the application, the part that goes

AND UPPER(complist.Station + '.' + complist.Slot) LIKE '%1.1%'

is added automatically if there's any value on a given field (i.e. 1.1).

I have a SQL syntax problem, but don't know how to solve it. Can anyone shed some light here?

thanks,

Gustavo

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

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

发布评论

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

评论(1

∞琼窗梦回ˉ 2024-12-10 18:58:03

如果没有错误消息,很难说出了什么问题,但我的赌注是隐式连接。尝试

SELECT  
   complist.CompName, 
   complist.CompID, 
   componenttrace.Remark, 
   complist.McID, 
   complist.Station, 
   complist.Slot, 
   complist.Amount - complist.Used - ISNULL(complist.Correction,0) 
FROM 
   complist
INNER JOIN componenttrace ON complist.CompID = componenttrace.CompID 
WHERE 
   complist.McID = 1004 
   AND UPPER(complist.Station + '.' + complist.Slot) LIKE '%1.1%'
ORDER BY 
   complist.CompName, complist.CompID

Without error message is very hard to say what is wrong, but my bet is on the implicit join. Try

SELECT  
   complist.CompName, 
   complist.CompID, 
   componenttrace.Remark, 
   complist.McID, 
   complist.Station, 
   complist.Slot, 
   complist.Amount - complist.Used - ISNULL(complist.Correction,0) 
FROM 
   complist
INNER JOIN componenttrace ON complist.CompID = componenttrace.CompID 
WHERE 
   complist.McID = 1004 
   AND UPPER(complist.Station + '.' + complist.Slot) LIKE '%1.1%'
ORDER BY 
   complist.CompName, complist.CompID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文