1

我有以下查询需要从 Oracel PL/SQL 转换为 T-SQL 以适应数据源更改。

Oracle 连接 (+) 如何转换为 T-SQL?

SELECT INA01 , SMYDESC , CASE WHEN INACONF = 'Y' THEN '0' ELSE '1' END  , INB15 , AZF03  , INAORIU  , ZX02  , INADATE  , INA04  , GEM02  , INA02  , INA11  , INA07  , INB03  , INB04  , IMA02 , INB09 , INB08 , INBUD02
       FROM INA_FILE , SMY_FILE , GEM_FILE , INB_FILE , IMA_FILE , AZF_FILE , ZX_FILE
       WHERE INA00 = '1'                                 
         AND INACONF <> 'X'
         AND INA01 = INB01
         AND INB04 = IMA01(+)
         AND SUBSTRING(INA01,1,5) = SMYSLIP(+)
         AND SUBSTRING(INA01,1,5) NOT IN ('0IN99','1IN03','0IN92','1IN04','0IN98')
         AND INA04             = GEM01(+)
         AND INB15             = AZF01(+)
         AND INAORIU           = ZX01(+)
         AND INACONF           = 'Y'                     
         AND inadate = to_date('2012/05/23', 'yyyy/mm/dd')
4

3 回答 3

2

您可能需要在 JOIN 子句中的列名前面添加表名:

SELECT INA01, SMYDESC, 
       CASE WHEN INACONF = 'Y' THEN '0' ELSE '1' END, 
       INB15, AZF03 , INAORIU , ZX02, INADATE, INA04, GEM02, INA02, 
       INA11, INA07, INB03, INB04, IMA02, INB09, INB08, INBUD02
FROM INA_FILE 
INNER JOIN INB_FILE ON INA01 = INB01
LEFT OUTER JOIN IMA_FILE ON INB04 = IMA01
LEFT OUTER JOIN GEM_FILE ON INA04 = GEM01
LEFT OUTER JOIN AZF_FILE ON INB15 = AZF01
LEFT OUTER JOIN SMY_FILE ON SUBSTRING(INA01,1,5) = SMYSLIP
LEFT OUTER JOIN ZX_FILE ON INAORIU = ZX01
WHERE INA00 = '1'                                 
AND INACONF <> 'X'
AND SUBSTRING(INA01,1,5) NOT IN ('0IN99','1IN03','0IN92','1IN04','0IN98')
AND INACONF = 'Y'                     
AND inadate = CONVERT(DATETIME, '05/23/2012', 101)
于 2012-05-23T08:51:16.027 回答
0

这是outer join运算符的本机 Oracle 语法。

http://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm

upd:为了帮助您实际重写此查询,我需要了解表结构,因为您在 where 子句中不使用任何表引用 - 只有列,这似乎是唯一的表。

于 2012-05-23T08:30:24.580 回答
0

我对您的架构做了一些假设......但是像这样

    SELECT  INA01 , SMYDESC , CASE WHEN INACONF = 'Y' THEN '0' ELSE '1' END  , INB15 , AZF03  , INAORIU  , ZX02  , INADATE  , INA04  , GEM02  , INA02  , INA11  , INA07  , INB03  , INB04  , IMA02 , INB09 , INB08 , INBUD02
    FROM    INA_FILE join inb_file on ina01 = inb01
            left join SMY_FILE on SUBSTRING(INA01,1,5) = SMYSLIP
            left join GEM_FILE on INA04 = GEM01
            join INB_FILE on INA01 = INB01
            left join IMA_FILE on INB04 = IMA01
            left join AZF_FILE on INB15 = AZF01
    WHERE   INA00 = '1'                                 
            AND INACONF <> 'X'
            AND SUBSTRING(INA01,1,5) NOT IN ('0IN99','1IN03','0IN92','1IN04','0IN98')
            AND INACONF = 'Y'                     
            AND inadate = '2012-05-23'
于 2012-05-23T08:43:58.563 回答