I want to create a view as follows:
CREATE view [dbo].[test] as
SELECT TEST.*
FROM OPENQUERY([MyServerLink],'LONGSELECTQUERY') as TEST;
The SELECT statement exceeds 8000 characters long which gives me that error:
SQL Error [103] [S0001]: The character string that starts with 'SELECT...' is too long. Maximum length is 8000.
How can I overcome that and create my view?
You can create a temporary table on the linked server and then use the temporary table
Example (MySQL)
EXEC('DROP TEMPORARY TABLE IF EXISTS TEMP_LONGSELECTQUERY') AT MyServerLink
EXEC('
CREATE TEMPORARY TABLE TEMP_LONGSELECTQUERY AS
LONGSELECTQUERY
') AT MyServerLink
SELECT * FROM OPENQUERY(MyServerLink, 'SELECT * FROM TEMP_LONGSELECTQUERY')
But, if the linked server is also a MSSQL Server you can make a select refering to the Server.Database.Schema.Table
:
SELECT
/******/
FROM MyServerLink.master.dbo.xxx x
join MyServerLink.master.dbo.yyy y /*****/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.