Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SELECT * FROM OPENDATASOURCE('SQLOLEDB','Data Source='+@SERVER_IP+';User ID=sa;Password=xxx').'EXEC '+@DB_NAME+' .dbo.get_MY'
这个查询有什么问题?
这是错误:
'+' 附近的语法不正确。期待')'
你在这里有一个语法错误:
User ID=sa;Password=xxx')
它应该是
User ID=sa;Password=xxx)'
所以你可以这样做:
SELECT * FROM OPENDATASOURCE('SQLOLEDB','Data Source='+@SERVER_IP+';User ID=sa;Password=xxx) EXEC '+@DB_NAME+'.dbo.get_MY'
在 xxx 之后有一个悬空的单引号。你的引号不平衡。