存储过程中的@ServerName [英] @ServerName on Stored Procedure

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

问题描述

我有存储过程,需要声明服务器名.保存我的存储过程后,我收到一条错误消息'.''附近的语法不正确.这是因为SELECT * FROM @servername.[数据库] .dbo.[表名].

I have stored procedure and needs to declare servername. When my stored procedure saved I have an error message "Incorrect syntax near ''.''." This is because SELECT * FROM @servername.[database].dbo.[tablename]. How do write the correct query using @servername?

推荐答案

从您的帖子中看来,@ServerName是本地过程变量,并且您试图动态生成查询并因此,您还需要动态执行它.有一个特殊的系统存储过程称为sp_executesql,可以为您完成此任务.
From your post it seems that @ServerName is local procedure variable and you are trying to generate your query dynamically and so you need to execute it dynamically too.There''s special system stored procedure called sp_executesql which could do that for you.


很遗憾,我需要在Crystal Report中执行该数据库设置为存储过程.
Unfortunately I needed to execute in crystal report that the database is set to stored procedure.


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

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