【问题标题】:SQL Server JDBC integration - query failing because of column nameSQL Server JDBC 集成 - 查询因列名而失败
【发布时间】:2016-03-17 18:25:31
【问题描述】:

我目前正在通过 JDBC 将一些数据从 SQL Server 数据库中提取到 ServiceNow 中。我遇到的问题是查询为某些列返回了空值。

我从 SNOW 运行的查询是

select [Capacity (Bytes)] 
from memory_table 

它为Capacity (Bytes) 列返回空值。在 SQL Server 数据库中,该表是使用列名为 Capacity (Bytes) 创建的,其中包含空格和括号,我认为这就是它返回 null 的原因。

我尝试在查询中的列名称周围添加方括号、双引号和单引号,但结果是相同的。如果我尝试使用表格中格式正确的另一列进行查询,它就可以正常工作。

任何帮助将不胜感激。

【问题讨论】:

    标签: sql-server integration servicenow altiris


    【解决方案1】:

    我怀疑您遇到了查询显示名称而不是列名称的问题,请通过 ServiceNow ODBC 驱动程序和工具测试您的查询以进行调试。 http://wiki.servicenow.com/index.php?title=Using_Interactive_SQL_With_ODBC

    我怀疑您的查询将返回错误,因为这可能是一个显示名称。例如,如果您查询 [Assignment group] 而不是 assignment_group,则会收到错误消息。

    select number, short_description, [Assignment group] from incident where number = 'INC0012345';
    

    结果

    The following error information describes the failure
    ODBC Call     = SQLPrepareW()
    SQL State     = 42S22
    Native error  = 10125(278D)
    Error Message = [SN][ODBC ServiceNow driver][OpenAccess SDK SQL Engine]Column:Assignment group not found.
    

    切换到列名将起作用

    select number, short_description, assignment_group from incident where number = 'INC0012345';
    

    结果

    NUMBER  short_description       assignment_group
    
    INC0012345      My incident short descrtiption     123b1c123f12f1234567e123b1234abc
    

    【讨论】:

    • 我的第一反应也是。 +1 因为这对于试图从 ServiceNow 中提取信息的人来说通常是一个很好的建议,但似乎这个人的问题是将信息从他们自己的 SQL Server 数据库中提取到 Servicenow。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多