怎么把数据库中字符串类型的1,2,3,4,5转换成批量删除的1,2,3,4,5
批量删除的存储过程!要接受一个id的集合1,2,3,4
eg:
IF EXISTS(SELECT * FROM SYSOBJECTS WHERE name='D_t_Base_Employee' AND xtype='P') DROP PROC D_t_Base_Employee
@str id varchar
GO
CREATE PROC D_t_Base_Employee
BEGN
DELETE Employee WHERE ID IN (@str)
END
在存储过程中应该怎样去吧varchar类型的参数转换成in类型
DELETE Employee WHERE ID IN (1,2,3,4) 转换 varcahr转换int
[解决办法]
方法一
CREATE PROC D_t_Base_Employee @str varchar(100)
as
declare @sql varchar(1000)
set @sql='DELETE Employee WHERE ID IN ('+@str+')'
exec (@sql)
go
方法二
CREATE PROC D_t_Base_Employee @str varchar(100)
as
DELETE Employee WHERE CHARINDEX(','+CAST(id as varchar)+',',','+@str+',')>0
go