在存储过程代码中调用sqlcmd命令 [英] Call sqlcmd commands in stored procedure code

查看:235
本文介绍了在存储过程代码中调用sqlcmd命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为链接服务器不容易发送openrowset查询,所以我直接通过SQLCMD模式连接到远程Sql Server.但这可以使用查询分析器来完成.当我将代码放入存储过程时,我什至无法保存它:

Because of Linked Server is not easy to send openrowset query I connect to remote Sql Server directly via SQLCMD mode. But this is Ok using Query Analyzer. When I put code to stored procedure I cannot even save it:

:Connect x.x.x.x -U sa -P password
select *
from  openrowset('VFPOLEDB','\\share\db\s_object.dbf';'';
    '','SELECT *  FROM s_object where i_class=21 order by 1')  

':'附近的语法不正确.

Incorrect syntax near ':'.

推荐答案

sqlcmd模式:connect语法在启用sqlcmd模式时在SSMS和QA中有效,但始终是客户端命令,由SSMS或QA本身执行,并且从未发送给引擎.因此,它绝不能像存储过程一样嵌入在服务器端模块中.如果您真的是说存储过程,那就难怪语法错误...

sqlcmd mode :connect syntax is valid in SSMS and QA when sqlcmd mode is enabled, but it will always be a client side command, executed by SSMS or QA itself and never sent to the engine. As such by no way it can be embedded on a server side module, like a stored procedure. If you really mean stored procedure then no wonder the syntax error...

这篇关于在存储过程代码中调用sqlcmd命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆