无法修复开放查询语法

时间:2019-06-23 06:29:59

标签: sql-server

DECLARE 
    @QueryString5 NVARCHAR(MAX),
    @OPENQUERY NVARCHAR(4000),
    @TSQL NVARCHAR(4000),
    @LinkedServer NVARCHAR(4000)

SET @LinkedServer = QuoteName('SQL-LAB-312')
SET @OPENQUERY = 'SELECT * FROM OPENQUERY('+ @LinkedServer + ','''
SET @TSQL = 'SELECT DISTINCT OBJECT_NAME(o.OBJECT_ID) AS TableName, p.row_count
             FROM SYS.objects o 
             JOIN SYS.schemas s ON o.schema_id = s.schema_id
             JOIN sys.dm_db_partition_stats p ON o.object_id = p.object_id
             JOIN LIVE.sys.tables t ON t.object_id = o.object_id
                                    AND t.is_tracked_by_cdc = 1
             WHERE o.type LIKE ''U''
                 s.name LIKE ''dbo''
             ORDER BY TableNa me'')'


EXEC (@OPENQUERY+@TSQL) 

运行上面的代码时,我收到以下错误消息。

  

第15层状态1线112消息
  'U'附近的语法不正确。

0 个答案:

没有答案