使用sql存储过程在表中插入多个复选框列表项的问题 [英] problem in inserting multiple items of check box list in table using sql stored procedure

查看:84
本文介绍了使用sql存储过程在表中插入多个复选框列表项的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好2全部...

i有一个表格,其中有三列

hello 2 all ...
i have a table in which there are three columns

id  ProductId    SubProductId
1    2            1
2    2            2 
3    2            3 
4    2            4 
5    2            5



i想写一个程序用于在上面给出的表中插入值

这里SubProductId值来自复选框列表(多个选择项)。

我想只使用一个变量来插入复选框列表表中的项目..



i googled internet,我找到了一个程序,并根据我自定义...



但是有一个问题我无法解决



我的程序是.....




i want to write an procedure for inserting values in table given above
here SubProductId values come from check box list (multiple selectd items).
and i want to use only one variable for inserting check box list items in table ..

i googled internet and i find a procedure for this and customize it according to me ...

but there is one problem which i unable to solve

my procedure is .....

alter procedure sp_checkboxTest
(
@S varchar(20)
)
as
begin
SET NOCOUNT ON;
--declare @S varchar(20) 

declare @sql varchar(max)
 while len(@S) > 0
 begin
 print left(@S, charindex(',', @S+',')-1) 
set @sql='insert into tblrmp values(''abc'','+left(@S, charindex(',', @S+',')-1)+')'  exec(@sql) 
set @S = stuff(@S, 1, charindex(',', @S+','), '')
 end 
 end





执行.... exec sp_checkboxTest '70,80, 90'这将给出结果如



on executing .... exec sp_checkboxTest '70,80,90' this will give result like

id  ProductId    SubProductId
1	abc	70
2	abc	80
3	abc	90



但我想通过在程序中传递参数来获得abc值...



如何解决这个问题。 ..请参阅


but i want abc value come from by passing parameter in procedure also ...

how to solve out this ... pls pls pls rply

推荐答案

看看这里:在SQL IN子句中使用逗号分隔值参数字符串 [ ^ ]


这篇关于使用sql存储过程在表中插入多个复选框列表项的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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