存储过程的动态参数 [英] Dynamic parameters to stored procedure
问题描述
我在为存储过程创建动态参数时遇到问题.我在存储过程中有两个 nvarchar
参数,它们是用逗号分隔的单词组合.例如:
I have a problem in creating dynamic parameters to stored procedure.
I have two nvarchar
parameters in a stored procedure that are combination of words separated with comma.
For example:
'Login, check, take, return' and 'admin, yes, no, yes'
我必须将这些参数包含在 where 子句中,如
I have to include these parameters in the where clause like
login=admin and check=yes and take=no and return=yes
问题在于参数中的字数是动态的.它可以从 1 到 20 个字不等.
The problem is that the number of words in the parameters are dynamic. It can vary from 1 to 20 words.
有没有办法解决这个问题?
Is there any solution to handle this?
推荐答案
- 定义 20 个参数,默认为 NULL
- 只设置你想要的
- 在 WHERE 子句中执行
(@Param IS NULL or Column = @Param)
- 你不应该使用存储过程
- 您需要为不同的用例编写更多的存储过程
如果您有完全动态的 SQL 和随机参数名称,那么它就是其中之一
If you have completely dynamic SQL and random parameter names then it's one of
您不会有一个完全动态的 .net 方法吧?
You wouldn't have a completely dynamic .net method would you?
这篇关于存储过程的动态参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!