【发布时间】:2013-12-09 03:20:20
【问题描述】:
我是 stackoverflow 新手,也是 DBFit 的新手。我已经成功完成了 DBFit 测试,但是在我的一个新测试中,我遇到了异常错误:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'as'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
at dbfit.fixture.Query.getDataTable(Query.java:40)
这是我正在测试的适合页面的一部分:
!3 Define ODS Query
!define ODSQuery { SELECT b.BrokerID
,b.BrokerCode as BC
FROM dbo.Broker b
}
!3 Define ODMart Query
!define ODMartQuery {select BrokerID
,BrokerCode as BC
from DSE_ODMART_TST_SIT.dbo.d1_Broker}
!3 Compare ODS vs. ODMart
| query |(${ODSQuery} EXCEPT ${ODMartQuery}) UNION (${ODMartQuery} EXCEPT ${ODSQuery})|
|BrokerID|BrokerCode|
我尝试不使用“AS”,仅使用“BrokerCode BC”为该列设置别名,但仍然存在不正确的语法异常错误。 如果我删除别名,只需“BrokerCode”,则适合测试通过。 如果我在 MSSSMS 中运行比较查询,所有 3 个版本都可以工作。
请注意,我的示例在第二个表中具有相同的列名 BrokerCode 只是为了使联合工作没有别名。但是我确实有其他列具有不同的列名,因此我需要进行别名工作。
我最近刚刚下载了最新的 DBFit 版本,我正在使用 miscrosoft 的 sqljdbc4.jar 作为 jdbc 驱动程序。
查询出了什么问题,如何在 DBFit 中使用 MSSQL 指定列别名?
提前致谢!
【问题讨论】:
标签: sql-server sql-server-2008 jdbc dbfit