SQL 语句不适用于 MS SQL 2005

SQL statement doesn't work for MS SQL 2005

这让我难住了。我从 i-net Clear Reports 复制并粘贴了一个 SQL 语句,并将其粘贴到一个 Windows 编辑器中,该编辑器正在编辑一个 Ubuntu .sql 文件,它只是一个文本文件。我已经通过 isql 和 Perl 毫无问题地连接到另一台 MS SQL 2005 服务器。所以我在处理一个包含大约 10 个连接的大 SQL 语句时遇到了问题,并将语句简化为这些多行:

SELECT PKG.SO_ID
FROM
   PACKAGES AS PKG
WHERE
    PKG.tracking_no = '640038823199'
;

此文件由多行组成,以 unix 行结尾。我的 isql 命令是:cat test1.sql | isql dsnname 'domain\username' password -v -b.

我将 -b 用于批处理模式,因为我正在通过文件向 isql 发送输入。 错误立即从第一行开始,但我仔细检查了语法,对于 SQL Server 2005,'AS' 在 'PACKAGES AS PKG' 中是可选的。

[37000][unixODBC][FreeTDS][SQL Server]Statement(s) could not be prepared.
[37000][unixODBC][FreeTDS][SQL Server]The multi-part identifier "PKG.SO_ID" could not be bound.
[ISQL]ERROR: Could not SQLExecute
[37000][unixODBC][FreeTDS][SQL Server]Incorrect syntax near the keyword 'FROM'.
[37000][unixODBC][FreeTDS][SQL Server]Statement(s) could not be prepared.
[ISQL]ERROR: Could not SQLExecute
[37000][unixODBC][FreeTDS][SQL Server]Incorrect syntax near the keyword 'AS'.
[37000][unixODBC][FreeTDS][SQL Server]Statement(s) could not be prepared.
[ISQL]ERROR: Could not SQLExecute
[37000][unixODBC][FreeTDS][SQL Server]Incorrect syntax near the keyword 'WHERE'.
[37000][unixODBC][FreeTDS][SQL Server]Statement(s) could not be prepared.
[ISQL]ERROR: Could not SQLExecute
[37000][unixODBC][FreeTDS][SQL Server]Incorrect syntax near '='.
[37000][unixODBC][FreeTDS][SQL Server]Statement(s) could not be prepared.
[ISQL]ERROR: Could not SQLExecute

谢谢。

默认情况下,isql 将每一行视为自己的查询,因此您需要将所有行合并到一行中。

isql 只是一个简单的测试应用程序,其设计目的不仅仅是为了证明连接和发出查询的快速简单方法。

以后的 isql 版本中的 -n 选项将更接近您想要的,在调用 SQLPrepare 之前查找以分号结尾的行。