2012-05-21 99 views
0
select * from table_name 
where BaseDocEntry=15 and BaseDocType='PRRH' and ItemCode='TestStudy2' 
    and WhseCode='01' and (currentdoctype<>'PUSH' and CurrentDocEntry<>15) 

根據我上面寫的查詢,從INS2數據將獲取排除currentdoctype [PUSH]和所有的數據,其中CurrentDocEntry不是15.我希望我的查詢是什麼,只有當該組合即currentdoctype = PUSH和CurrentDocEntry = 15出現在同一行中時,它才必須排除該數據,然後排除該行。排除記錄驗證兩個條件

你能解決這個問題嗎?

+3

請不要用*什麼*您的要求來標題您的問題。 –

+0

我試圖讓一個更清晰的標題,但我不是100%確定我真的明白這個問題。請確認。 –

回答

8

使用此:

and not (currentdoctype='PUSH' and CurrentDocEntry=15) 
+0

謝謝。它解決了 – Shruti

1

由於您使用AND而不是OR如果希望在currentdoctype是「推」和CurrentDocEntry不同於15

不同的查詢被排除currentdoctype = PUSH和CurrentDocEntry = 15只是把這些條件代替:

select * from ins2 
where BaseDocEntry=15 and BaseDocType='PRRH' and ItemCode='TestStudy2' 
and WhseCode='01' and (currentdoctype='PUSH' and CurrentDocEntry=15) 
0

在某些情況下,不工作可以使用簡單的案例和where子句來解決它。這將只排除那些currentdoctype ='PUSH'和CurrentDocEntry = 15的情況。

SELECT *, 
CASE 
WHEN currentdoctype ='PUSH' AND CurrentDocEntry = 15 THEN 'c1' 
ELSE 'c2' 
END AS com_con 
FROM table_name 
WHERE BaseDocEntry=15 AND BaseDocType='PRRH' AND ItemCode='TestStudy2' 
    AND WhseCode='01' AND com_con = 'c2';