MSSQL链接服务器为列提供了不一致的元数据

时间:2015-02-26 09:45:02

标签: sql-server postgresql

我在MSSQL中遇到一个难以运行的'SUM'语法,这个连接服务器(PostgreSQL)是通过ODBC驱动程序创建的连接。

如果我只检索数据,则没有任何问题,

select * from OpenQuery([192.168.1.145],'
    select party_code, amount_forex from biv_so_main
')

如果我尝试对值求和,则会抛出错误,

select * from OpenQuery([192.168.1.145],'
    select party_code, sum(amount_forex) from biv_so_main group by party_code
')

错误消息

The OLE DB provider "MSDASQL" for linked server "192.168.1.145" supplied inconsistent metadata for a column. The column "sum" (compile-time ordinal 2) of object " select party_code, sum(amount_forex) from biv_so_main group by party_code " was reported to have a "SCALE" of 6 at compile time and 2 at run time.

我google了很多,似乎没有人像我一样有问题,任何人都可以帮忙吗?

感谢。

1 个答案:

答案 0 :(得分:2)

为sum列添加一个别名并转换为数据类型(对于任何类型的amount_forex)。

select * from OpenQuery([192.168.1.145],'
    select party_code
         , sum(amount_forex)::int amount_forex_sum 
    from biv_so_main group by party_code
')