如何根据SQL Server数据库筛选查询中的值?

时间:2011-09-09 13:34:50

标签: sql-server syntax sql-like

我的查询对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语法问题,但不知道如何解决它。有人能在这里说清楚吗?

感谢,

古斯塔沃

1 个答案:

答案 0 :(得分:-1)

没有错误信息很难说是什么问题,但我的赌注是隐式加入。尝试

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