存储过程批量更新问题 急~
存储过程
-----------------------
alter PROCEDURE [dbo].[sp_Book_UpdateChapterAllEditorDo]
@BookID int,
@VolumeIDList nvarchar(2000),
@ChapterIDList nvarchar(2000),
@EditorDo char(1)
AS
SET NOCOUNT ON
UPDATE [dbo].[Book_Chapter] SET
EditorDo = @EditorDo
WHERE
[BookID] = @BookID and VolumeID in (@VolumeIDList) and ChapterID in (@ChapterIDList)
--------------------------------------------------
exec [sp_Book_UpdateChapterAllEditorDo] 701242, '1691,1690 ', '5905,5906,5907,5908 ', '6 '
执行后提示在将nvarchar 值 '5905,5906,5907,5908 ' 转换成数据类型int 时失败
ChapterID 这个字段是一个整型 但是用参数传递进来是一个拼接的字符串是不是不能这么写 还是有其他的方法?
------解决方案--------------------把需要执行的update语句写在字符串里面,然后exec(@Str)
------解决方案--------------------alter PROCEDURE [dbo].[sp_Book_UpdateChapterAllEditorDo]
@BookID int,
@VolumeIDList nvarchar(2000),
@ChapterIDList nvarchar(2000),
@EditorDo char(1)
AS
declare @SQL nvarchar(2000)
SET NOCOUNT ON
set @SQL = 'UPDATE [dbo].[Book_Chapter] SET
EditorDo = ' ' '+@EditorDo+ ' ' '
WHERE
[BookID] = '+cast(@BookID as varchar)+ ' and VolumeID in ( '+@VolumeIDList+ ') and ChapterID in ( '+@ChapterIDList+ ') '
print @SQL
exec @SQL