在存储过程中如何在excecute存储过程中存储列表类型值(我们将输入作为复选框列表值) [英] In stored procedure how to store list type values in excecute stored procedure (input we are taking as checkbox list values)
本文介绍了在存储过程中如何在excecute存储过程中存储列表类型值(我们将输入作为复选框列表值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@DropDownList = 'Product' ,(for single vales)
@ProductName = 'name' ,(for single vales)
@Price = 1000 , (for single vales)
@list = '?' (for multiple values)
@list is a list type string variable
我尝试过:
我尝试过单输入类型ex:@ list ='M';
i需要多个值,如Ex:@ list ='M' ,'L','S';
i在给出多个值时遇到问题。
如果我给这样的话
What I have tried:
I have tried for single input type ex: @list= 'M';
i need multiple values like Ex: @list= 'M', 'L', 'S';
i am facing problem in giving multiple values.
if i give like this
@list = 'M', @list = 'L', @list = 'S'
ERORR -
ERORR--
Procedure or function Stored Procedure has too many arguments specified.
推荐答案
根据你想要对存储中的列表做什么,有几种方法可以实现这一点。过程。
- 假设您使用的是SQL Server 2008或更高版本,您可以传入用户定义表:请参阅此帖子中的Redth解决方案C#SQL Server - 将列表传递给存储过程 [ ^ ]
- 你可以在数据库上有一个永久表,你可以在调用SP之前填充它。
- 您可以传入CSV作为nvarchar
参数,例如M,L,P。这有助于将其用作IN
子句的一部分,但是您需要构造一些动态SQL才能使用它 - 请参阅动态SQL简介(第1部分) - SQLTeam.com [ ^ ]
There are a couple of ways of achieving this depending on what you want to do with the list within the Stored Procedure.
- Assuming you are using SQL Server 2008 or later, you can pass in a User Defined Table: See the solution from Redth on this post C# SQL Server - Passing a list to a stored procedure[^]
- You could have a permanent table on the database which you could populate before calling the SP.
- You could passing in a CSV as annvarchar
parameter e.g. 'M,L,P'. This lends itself to use as part of anIN
clause but you will need to construct some Dynamic SQL in order to use it - see Introduction to Dynamic SQL (Part 1) - SQLTeam.com[^]
这篇关于在存储过程中如何在excecute存储过程中存储列表类型值(我们将输入作为复选框列表值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文