Querying a ODBC Linked Server from MSSQL

When trying to browse a linked server in MSSQL through Microsoft SQL Server Management Studio I got an error from the GUI "[LinkedServerName]...[TableName] contains no columns that can be selected or the current user does not have permissions on that object." What tha? I confirmed that the user had access through checking the properties on the connection. So what else? I tried querying it from the Query Editor directly... select * from [LinkedServerName]...[TableName] This gave another error "OLE DB Provider "MSDASQL" for linked Server "[LinkedServerName]" returned an invalid definition for table "[TableName]". WHAT THA? Ok, so did some more digging on this error and found that the error was being caused because the underlying Linked Server did not support TSQL statements. I think the linked server doesn't like the ...[TableName] portion of the query. Hmmm, so how do you get around this? Turns out there is syntax to wrap the query! SELECT * FROM OPENQUERY([LinkedServerName],'select * from [TableName]') Sweet, now it works.

Comments

Popular posts from this blog

PHP timezones explained

iPhone Internet Tethering settings