使用 SELECT AS 别名和内部联接在 TSQL 上出现 DB2 错误

发布于 2024-09-08 14:49:10 字数 1238 浏览 7 评论 0原文

我正在使用链接服务器在 LINUX 机器 (DB2/LINUXX8664) 上的 DB2 数据库上编写 T-SQL 程序。我认为 DB2 的版本是 9.5.3 但不确定。我收到一个错误,我认为这可能是 DB2 问题,因为 T-SQL 中的语法检查正常。这是代码:

IF(SELECT(OBJECT_ID('TEMPDB..#TempFile))) IS NOT NULL DROP TABLE #TempFile

SELECT        *

INTO  #TempFile
FROM  OPENQUERY(LinkedServer, '

SELECT  F.LOAN_NUMBER,

   (SELECT 
    SUM(EXP_CHILD_CARE_AMOUNT) + SUM(EXP_FOOD_AMOUNT) + 
    SUM(EXP_LIFE_INSURANCE_AMOUNT) + SUM(EXP_TRANSPORTATION_AMOUNT) + SUM(EXP_TUITION_AMOUNT)+
    SUM(EXP_USER_1_AMOUNT) + SUM(EXP_USER_2_AMOUNT) + SUM(EXP_USER_3_AMOUNT) + 
    SUM(EXP_UTILITIES_AMOUNT)
    FROM FINANCIAL F)
       AS ExpenseTotal,

    (SELECT
     SUM(MORTGAGOR_NET_PAY_AMOUNT) + SUM(MORTGAGOR_OTHER_INCOME_AMOUNT) AS IncomeTotal 
     FROM FINANCIAL F   
      INNER JOIN BDE.LOAN_V a ON F.LOAN_NUMBER = A.LOAN_NUMBER)
     WHERE A.FIRST_PRINCIPAL_BALANCE> 0
        GROUP BY F.LOAN_NUMBER 
        ORDER BY F.LOAN_NUMBER,   


FETCH ONLY WITH UR ')

这是错误:

链接服务器“LINKEDSERVER”的 OLE DB 提供程序“MSDASQL”返回消息“[IBM][CLI Driver][DB2/LINUXX8664] SQL0104N 在“BER) WHERE”之后发现意外标记“A”。预期标记可能包括:“来自”。 ”。 消息 7350,16 级,状态 2,第 4 行 无法从链接服务器“LINKEDSERVER”的 OLE DB 提供程序“MSDASQL”获取列信息。

I am writing a T-SQL program over a DB2 database on a LINUX box (DB2/LINUXX8664) using a linked server. I think the DB2 is Version 9.5.3 but not certain. I am receiving an error that I feel is likely a DB2 issue as the syntax checks out okay in T-SQL. This is the code:

IF(SELECT(OBJECT_ID('TEMPDB..#TempFile))) IS NOT NULL DROP TABLE #TempFile

SELECT        *

INTO  #TempFile
FROM  OPENQUERY(LinkedServer, '

SELECT  F.LOAN_NUMBER,

   (SELECT 
    SUM(EXP_CHILD_CARE_AMOUNT) + SUM(EXP_FOOD_AMOUNT) + 
    SUM(EXP_LIFE_INSURANCE_AMOUNT) + SUM(EXP_TRANSPORTATION_AMOUNT) + SUM(EXP_TUITION_AMOUNT)+
    SUM(EXP_USER_1_AMOUNT) + SUM(EXP_USER_2_AMOUNT) + SUM(EXP_USER_3_AMOUNT) + 
    SUM(EXP_UTILITIES_AMOUNT)
    FROM FINANCIAL F)
       AS ExpenseTotal,

    (SELECT
     SUM(MORTGAGOR_NET_PAY_AMOUNT) + SUM(MORTGAGOR_OTHER_INCOME_AMOUNT) AS IncomeTotal 
     FROM FINANCIAL F   
      INNER JOIN BDE.LOAN_V a ON F.LOAN_NUMBER = A.LOAN_NUMBER)
     WHERE A.FIRST_PRINCIPAL_BALANCE> 0
        GROUP BY F.LOAN_NUMBER 
        ORDER BY F.LOAN_NUMBER,   


FETCH ONLY WITH UR ')

Here is the error:

OLE DB provider "MSDASQL" for linked server "LINKEDSERVER" returned message "[IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token "A" was found following "BER) WHERE". Expected tokens may include: "FROM". SQLSTATE=42601
".
Msg 7350, Level 16, State 2, Line 4
Cannot get the column information from OLE DB provider "MSDASQL" for linked server "LINKEDSERVER".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白日梦 2024-09-15 14:49:10

<代码>= A.LOAN_NUMBER)
其中 A.FIRST_PRINCIPAL_BALANCE> 0 - 该括号看起来不合适。

= A.LOAN_NUMBER)
WHERE A.FIRST_PRINCIPAL_BALANCE> 0
- that bracket looks out of place.

妄想挽回 2024-09-15 14:49:10

我注意到的第一件事是你有一个裸查询,这在 Microsoft SQL Server 中并不罕见。链接查询的简化版本如下所示:

SELECT (subquery), (subquery) WHERE ...conditions...

在 DB2 中,任何查询中都必须有 FROM 子句。 Microsoft 和其他一些 SQL 供应商允许使用不带 FROM 子句的 SELECT,但这不是标准 SQL。在这种情况下,DB2 符合标准。


我注意到的第二件事:

IF(SELECT(OBJECT_ID('TEMPDB..#TempFile))) IS NOT NULL DROP TABLE #TempFile

您需要关闭那个带引号的字符串吗?

The first thing I notice is that you have a naked query, which is not uncommon in Microsoft SQL Server. A simplified version of your linked query looks like this:

SELECT (subquery), (subquery) WHERE ...conditions...

In DB2, you must have a FROM clause in any query. Microsoft and some other SQL vendors permit a SELECT with no FROM clause, but this isn't standard SQL. In this case, DB2 conforms to the standard.


Second thing I notice:

IF(SELECT(OBJECT_ID('TEMPDB..#TempFile))) IS NOT NULL DROP TABLE #TempFile

Do you need to close that quoted string?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文