我如何更改“用户类型"?存储过程中的参数设置? [英] How Can I Alter "user type" of Paramter in stored procedure?

查看:93
本文介绍了我如何更改“用户类型"?存储过程中的参数设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正在基于基于运行时创建的动态SQL的小型项目中工作,

我在如何更改特定存储过程中特定参数的数据类型时遇到问题

考虑到我已找到问题的解决方案,但在此链接的表中
http://efreedom.com/Question/1-1383494/Alter-User-定义类型的SQL服务器

因此,除了存储过程或任何解决方案外,我如何才能使解决方案接近于此解决方案.
谢谢,

Dear All,

I am Working In Small Project Based On Dynamic SQL Created On Run Time,

And I Have A problem in How Can i Alter The Data Type Of specific Parameter In specific Stored Procedure

With Considering That I have Found a Solution Of My Problem But In Table In This Link
http://efreedom.com/Question/1-1383494/Alter-User-Defined-Type-Sql-Server

So ,How Can i Make a solution Near To this solution but for stored Procedure Or Any Solution.

Thanks,

推荐答案

您是否考虑过不使用存储过程?您说过要在运行时创建动态SQL,为什么不对数据库运行它呢?

如果必须通过存储过程运行它,则可以使用sp_executesql存储过程.查看 MSDN文档 [
Have you considered not using stored procedures? You said that you''re creating dynamic SQL at run time, why not just run that against the DB?

If you have to run it through a stored procedure, you could use sp_executesql stored procedure. Check out the MSDN documentation[^]. Sorry if this isn''t what you''re after. Just trying to help out!

Hogan


嘿,
如果我正确理解了您的问题.我的想法是一件事.

假设"spFoo"是您的存储过程.您可以通过执行以下命令来获取完整的sp代码.

sp_HelpText spFoo

将结果存储在字符串构建器对象/String中.

string strCommand=(result from above command)

从上面的命令返回的结果将是sp的Create命令.但是这里我们需要一个Alter命令.因此我们首先将strCommand中第一次出现的"Create"替换为"Alter".其次,假设您有一个名为"@Parameter"的参数
用所需的名称替换字符串中的"@Parameter".
例如.
strCommand.Replace("@Parameter","@NewParameterName");

然后执行具有命令text = strCommand
的SQLCommand (现在有了sql代码,可以使用新的参数名称来更改该过程.)

然后你就去了.
希望对您有所帮助.如果您有任何进一步的疑问,请与我联系.
问候
阿三


如果信息有用,请不要忘记将其标记为已回答.谢谢
Hey,
If i have understood your problem correctly. I have one thing in my mind to do that.

Lets assume that "spFoo" is your stored procedure.you can get the complete sp code by executing the following command.

sp_HelpText spFoo

store the result in a string builder object /String.

string strCommand=(result from above command)

The result returned from the above command will be the Create command of the sp. but here we need an Alter command. so we will first replace the first occurance of "Create" in the strCommand with "Alter".Secondly,lets assume you have a parameter named "@Parameter"
Replace "@Parameter" in the string with the name you want.
eg.
strCommand.Replace("@Parameter","@NewParameterName");

and then execute an SQLCommand having command text= strCommand
(which now has the sql code to alter the procedure with your new parameter name.)

and there you go.
Hope this will help you.Let me know if you have any furthur query.
Regards
Ahsan


Dont forget to mark as answered if the info was useful.Thanks


这篇关于我如何更改“用户类型"?存储过程中的参数设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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