ODBC报SQL type -155错误,请求修正SQL查询解决时间格式兼容问题
解决ODBC执行SQL时报错“ODBC SQL type -155 is not yet supported”的问题
原查询在SQL Server Management Studio中可正常运行,但通过ODBC执行时抛出错误:“('ODBC SQL type -155 is not yet supported. column-index=6 type=-155', 'HY106')”
原查询语句:
select top 100 SType, * from dw.execution f join dw.station d on f.StID = d.StID where SType like '%test%'
问题根源是第6列TestSuiteStartTimestampUtc的时间类型不被ODBC支持,以下是两种修正方案:
方案1:移除不支持的列
由于不需要该列,需避免使用*(会自动包含所有列),改为显式列出需要的所有列,排除TestSuiteStartTimestampUtc:
select top 100 d.SType, -- 列出dw.execution表中除TestSuiteStartTimestampUtc外的所有字段 f.StID, f.ExecutionID, f.OtherColumn1, f.OtherColumn2, -- 列出dw.station表需要的字段 d.StationName, d.Location, d.OtherColumn3 from dw.execution f join dw.station d on f.StID = d.StID where d.SType like '%test%'
方案2:将该列转换为字符类型
把不被支持的时间列通过CAST转换为字符串类型,同时保留其他列(需显式处理目标列,避免*引入原始类型):
select top 100 d.SType, -- 将时间列转换为nvarchar类型 CAST(f.TestSuiteStartTimestampUtc AS nvarchar(100)) as TestSuiteStartTimestampUtc, -- 列出dw.execution表的其他字段 f.StID, f.ExecutionID, f.OtherColumn1, -- 列出dw.station表的所有字段 d.* from dw.execution f join dw.station d on f.StID = d.StID where d.SType like '%test%'
注意:如果不确定所有列名,可以通过sp_columns dw.execution和sp_columns dw.station查询表结构,再按需列出字段。
内容的提问来源于stack exchange,提问作者Mich
相关产品推荐
相关产品推荐

