2

我正在尝试从 SQL Server 访问存储在 MySQL 上的数据。我已按照本网站 http://www.sqlservercentral.com/Forums/Topic340912-146-1.aspx上的说明进行操作

我创建了没有问题的链接服务器,但是当我尝试使用 OPENQUERY 选择数据时,出现以下错误

Msg 7357, Level 16, State 2, Line 1
Cannot process the object "
SELECT
CAST(t.name AS CHAR) AS team_name,
CAST(TRIM(REPLACE(CONCAT(su.first_name, " ", su.middle_name , " ", su.last_name), " ", " ")) AS CHAR) AS fullname,
CAST(su.login_user AS CHAR) AS username,
CAST(t.billing_department_id AS UNSIGNED) AS billing_dept_id
FROM my_table.users AS su
INNER JOIN my_table.teams AS t ON t.team_id = su.team_id
WHERE client_id = 1 ". The OLE DB provider "MSDASQL" for linked server "SQLSERVER_1" indicates that either the object has no columns or the current user does not have permissions on that object.

这是我的查询

SELECT * FROM OPENQUERY(SQLSERVER_1, '
SELECT
CAST(t.name AS CHAR) AS team_name,
CAST(TRIM(REPLACE(CONCAT(su.first_name, " ", su.middle_name , " ", su.last_name), " ", " ")) AS CHAR) AS fullname,
CAST(su.login_user AS CHAR) AS username,
CAST(t.billing_department_id AS UNSIGNED) AS billing_dept_id
FROM my_table.users AS su
INNER JOIN my_table.teams AS t ON t.team_id = su.team_id
WHERE client_id = 1 ') AS su

有人能告诉我这有什么问题吗,我能做些什么来解决这个错误?

谢谢

4

2 回答 2

2

我终于解决了这个问题。解决方案非常愚蠢,但我无法相信这是解决方案。解决方法是简单的去掉 MySQL select 和单引号之间的空格。所以它变成 'SELECT CAST(t.name AS CHAR) AS team_name, ........

于 2013-07-18T19:53:28.930 回答
0

我遇到了同样的问题,但直到我们升级到 MySQL ODBC 5.3 驱动程序之后。由于我们有很多关于新行的现有查询,我花了一些时间试图找到一个修复程序。原来问题是由使用驱动程序的 unicode 版本引起的。一旦我切换到 ANSI,问题就消失了。

于 2015-10-20T17:23:55.127 回答