SQL openrowset中可以查询本地表吗?

来源:百度知道 编辑:UC知道 时间:2024/05/18 03:37:51
select * from OPENROWSET('SQLOLEDB', 'server=192.168.1.5;uid=sa;pwd=xxx;database=xxx',
'select * from product where product_no not in ('''+ select product_no from product +''')')

执行错误,不知道怎么在openrowset中加入本地表条件,请大大指点,谢谢
顶,哪位大大知道,请帮忙啊,谢谢wuyixiong1987 大大
不过想再问问这个调用怎么写
where product_no not in ('''+ select product_no from product +''')
'''+ select product_no from product +'''这里总是出错

可以的
你要先开启外围服务器配置
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
然后执行你的代码
select * from OPENROWSET('SQLOLEDB', 'server=localhost;uid=sa;pwd=xxx;database=xxx',
'select * from product where product_no not in ('''+ select product_no from product +''')')
如果你的MSSQL是默认实例的话
server=localhost就可以了
否的话
server=localhost\你自己的实例名

用完后不用了的话可以关闭
--关闭跨服务器访问
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure