根据ID删除一个信息的存储过程
alter PROCEDURE [dbo].[pro_allTable]
@tableName varchar(100),--表名
@Id int --ID号
as
declare @sql varchar(1000)
Set nocount on
set @sql=N 'DELETE FROM '+@tableName+ N ' WHERE [ID]= '+@id
exec sp_executesql @sql
go
出错
将 nvarchar 值 'DELETE FROM TABLE1 WHERE [ID]= ' 转换为数据类型为 int 的列时发生语法错误。
哪位大哥帮忙看一下
------解决方案--------------------set @sql= 'DELETE FROM '+@tableName+ ' WHERE [ID]= '+ RTRIM(@id)
------解决方案--------------------set @sql=N 'DELETE FROM '+@tableName+ N ' WHERE [ID]= '+ cast(@id as varchar(10))
一个varchar与一个int相加,不报错才怪
------解决方案--------------------set @sql= 'DELETE FROM '+@tableName+ ' WHERE [ID]= '+ TRIM(@id)