2011-09-09 87 views
0

我有一個針對MySQL數據庫運行正常的查詢,但我們必須將數據庫和應用程序遷移到SQL Server。現在,我無法使此查詢生效。如何篩選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語法問題,但不知道如何解決它。任何人都可以在這裏發光?

感謝,

古斯塔沃

+7

準確的錯誤消息?我將查詢複製/粘貼到SSMS中,它對我來說解析得很好。 –

+0

是'Station'和'Slot'兩個varchar? –

+0

@ M.R。,實際上,這是問題,兩個字段都是int。我通過添加一個CAST(complist.Station AS VARCHAR)和CAST(complist.Slot AS VARCHAR)來獲得它的工作。 – gtludwig

回答

-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 
+0

我通過添加CAST(complist.Station AS VARCHAR)和CAST(complist.Slot AS VARCHAR。得到它的工作。我的壞!謝謝你的時間!:) – gtludwig