2013-11-20 74 views
1

我在我的SQL中出現了一些錯誤,無法找出造成問題的原因。我正在使用Navicat連接到SQL Server 2000(在Windows Server 2003上)。我運行以下命令:SQL Server查詢SAP Business One

SELECT DISTINCT 
OCRD.CardCode, 
OCRD.CardName, 
OCRD.Address, 
OCRD.ZipCode, 
OCRD.City, 
OCRD.Country, 
CASE OCRD.GroupCode = 
WHEN 100 THEN 'Kunde' 
WHEN 101 THEN 'Lieferant' 
END 
FROM 
OCRD 
INNER JOIN OINV T1 on T1.CardCode = OCRD.CardCode 
WHERE 
(OCRD.GroupCode != 101) AND 
(OCRD.GroupNum = 8 OR 
OCRD.GroupNum = 7 OR 
OCRD.GroupNum = 9 OR 
OCRD.GroupNum = 6 OR 
OCRD.GroupNum = 5 OR 
OCRD.GroupNum = 4) AND 
T1.DocDate > '2012-01-01 00:00:00.000' AND 
OCRD.Address IS NOT NULL AND 
(validFor = 'N' OR (validFor = 'Y' AND validTo IS NULL)) 

以下錯誤出現

[錯誤] 42000 - [SQL服務器]語法錯誤附近 '='

我想不通爲什麼

+0

沒有SQL Server ** 2003 ** - 我們有2000,2005,2008,2008 R2,2012和2014年在地平線上 - 所以這是什麼真的嗎?= –

+0

它在2000 Server 2003上運行。對不起 – Dreshar

回答

2

使用此

SELECT DISTINCT 
    OCRD.CardCode, 
    OCRD.CardName, 
    OCRD.Address, 
    OCRD.ZipCode, 
    OCRD.City, 
    OCRD.Country, 
    CASE OCRD.GroupCode   -- you must not use a = here ! 
     WHEN 100 THEN 'Kunde' 
     WHEN 101 THEN 'Lieferant' 
    END 
FROM 
    OCRD 
INNER JOIN 
    OINV T1 on T1.CardCode = OCRD.CardCode 
WHERE 
    (OCRD.GroupCode != 101) AND 
    (OCRD.GroupNum = 8 OR 
    OCRD.GroupNum = 7 OR 
    OCRD.GroupNum = 9 OR 
    OCRD.GroupNum = 6 OR 
    OCRD.GroupNum = 5 OR 
    OCRD.GroupNum = 4) AND 
    T1.DocDate > '2012-01-01 00:00:00.000' AND 
    OCRD.Address IS NOT NULL AND 
    (validFor = 'N' OR (validFor = 'Y' AND validTo IS NULL)) 

有沒有=CASE行末行代碼

+0

謝謝 - 應該知道這大聲笑:) – Dreshar