我正在尝试从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
有人可以告诉我这有什么问题,我该怎么做才能解决这个错误?
由于
答案 0 :(得分:2)
我终于解决了这个问题。解决方案非常愚蠢,但我不相信它是解决方案。解决方案是简单删除MySQL select和单引号之间的空格。因此它变为' SELECT CAST(t.name AS CHAR)AS team_name,........
答案 1 :(得分:0)
我遇到了同样的问题,但直到我们升级到MySQL ODBC 5.3驱动程序之后才这样。由于我们在新行中有很多现有查询,因此我花了一些时间来寻找修复。原来问题是由使用unicode版本的驱动程序引起的。一旦我切换到ANSI,问题就消失了。