1

我有一个查询正在我的水晶报告中使用。这部分:“AND( BIKEYC IN ('GBC13', 'GBV13', 'GBV11', 'GBC11')"

现在已更改,他们会将这些代码发布到表格中。我创建了一个包含这些代码的视图,称为 globkeys。它包含 2 个列,第二个是键,它被称为“BFKEYC”。我需要在查询中包含此表,以便选择 BIKEYC,而不是当它是“IN”该组时,而是当它在 globkeys 中匹配时。

SELECT                                                                       
  ALL       T01.BIENT#, T03.ADENTN, T03.ADFNM, T03.ADLNM, T01.BIKEYC,        
            T01.BISTPD, T02.OHORDD, T02.OHORD#, T02.OHORDT, T02.OHTTN$       
  FROM      ASTDTA.DRCST1 T01,                                               
            ASTDTA.OEORH1 T02,                                               
            ASTDTA.ADRES1 T03                                                
  WHERE     BIENT# = OHENT#                                                  
    AND     BIENT# = ADENT#                                                  
    AND(    BIKEYC IN ('GBC13', 'GBV13', 'GBV11',  'GBC11')                                     
    AND     OHORDD > BISTPD                                                  
    AND     OHORDT NOT IN ('QTE', 'CQO', 'COR', 'COE', 'SAM')                
    AND     ADSFX# = '000')                                                  
  ORDER BY  T01.BIKEYC ASC, T01.BIENT# ASC             
4

1 回答 1

1

您可以使用 INNER JOIN 或内联查询

方法 1: 替换以下语句

AND(    BIKEYC IN ('GBC13', 'GBV13', 'GBV11',  'GBC11')  

AND(    BIKEYC IN (SELECT BFKEYC FROM GlobKeys)

方法二:

SELECT                                                                       
  ALL       T01.BIENT#, T03.ADENTN, T03.ADFNM, T03.ADLNM, T01.BIKEYC,        
            T01.BISTPD, T02.OHORDD, T02.OHORD#, T02.OHORDT, T02.OHTTN$       
  FROM      ASTDTA.DRCST1 T01,                                               
            ASTDTA.OEORH1 T02,                                               
            ASTDTA.ADRES1 T03,
            GlobKeys G                                               
  WHERE     BIENT# = OHENT#                                                  
    AND     BIENT# = ADENT#                                                  
    AND(    BIKEYC = G.BFKEYC                                     
    AND     OHORDD > BISTPD                                                  
    AND     OHORDT NOT IN ('QTE', 'CQO', 'COR', 'COE', 'SAM')                
    AND     ADSFX# = '000')                                                  
  ORDER BY  T01.BIKEYC ASC, T01.BIENT# ASC 
于 2013-10-21T21:50:07.900 回答