1

我正在尝试使用 SQL 服务器 OPENQUERY 函数从 Mysql 服务器中提取数据。当我运行查询来计算 w mysql 服务器中的记录时,我得到的值没问题

-this query works and it return the total records found
SELECT count(*) AS total  FROM OPENQUERY(LinkedServer, 'SELECT * FROM mydb_name.users')

但是当我这样做时

SELECT login_user FROM OPENQUERY(LinkedServer, 'SELECT * FROM mydb_name.users')

我收到这个错误

Msg 7347, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' for linked server 'LinkedServer' returned data that does not match expected data length for column '[MSDASQL].login_user'. The (maximum) expected data length is 60, while the returned data length is 16.

我试过但没用

SELECT CONVERT(CHAR(60), login_user) AS name  FROM OPENQUERY(LASWEB, 'SELECT * FROM mydb_name.users')

我假设这是一个数据类型问题,但我该如何解决呢?如何提取我需要的数据?

谢谢

4

2 回答 2

2

像这样工作的变量

SELECT login_user  FROM OPENQUERY(LASWEB, 'SELECT CAST(u.login_user AS CHAR) AS login_user  FROM mydb_name.users AS u')
于 2013-04-29T17:56:22.753 回答
0

试试这个: SELECT * FROM OPENQUERY(LinkedServer, 'SELECT login_user FROM mydb_name.users')

于 2018-07-13T16:34:37.077 回答