例:
SELECT * FROM OPENROWSET ('sqlOLEDB','srv'; 'login'; 'mdp'; 'SELECT * FROM Case WHERE ID = ' + @caseID)
但是,当我这样做时,我得到错误:”附近的语法不正确
我该如何构建查询?谢谢
我担心,你必须构建一个动态查询,它将调用OPENROWSET,如下所示:
SET @sql = ' SELECT * FROM OPENROWSET (''sqlOLEDB'',''srv''; ''login''; ''mdp''; ''SELECT * FROM Case WHERE ID = ' + @caseID + ''')'; EXEC(@sql);