类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
参考:
http://community.csdn.net/Expert/topic/3453/3453921.xml?temp=.7766992
我想将表名传递过去:但是发现这么写不行啊
CREATE PROC MoveSortId
@SortId int, --要处理的id --功能:动态的调整表中的排序编号
@Arrow nvarchar(10) , --移动方向,上表示上移,下表示下移
@Table nvarchar(15) --相关表名
as
declare @nid int
exec (select +@nid+=case when up=up then min(SortId) else max(SortId) end from + @Table)
--如果不可移动,则退出
if @SortId=@nid return
--取得移动后的新 SortId 值
set @nid=@SortId+case when @Arrow=up then -1 else 1 end
--更新 SortId
exec (update + @Table + set SortId=case when SortId= + @SortId + then + @nid + else + @SortId + end
where SortId in( + @SortId + , + @nid + ))
GO
问题出在
exec (select +@nid+=case when up=up then min(SortId) else max(SortId) end from + @Table)
这句里面需要返回+@nid,但是这么执行总报错阿
网友回答:
--存储过程
create proc p_move
@SortId int, --要处理的id
@方向 char(1)=下, --移动方向,上表示上移,下表示下移
@Table nvarchar(15) --相关表名
as
declare @s nvarchar(4000)
set @s=
declare @nid int
select @nid=+case when @方向=上 then min(SortId) else max(SortId) end
+from [+@Table+]
--如果不可移动,则退出
if @SortId=@nid return
--取得移动后的新 SortId 值
set @nid=@SortId++case when @方向=上 then -1 else 1 end
+
--更新 SortId
update [+@Table+] set SortId=case when SortId=@SortId then @nid else @SortId end
where SortId in(@SortId,@nid)
exec sp_executesql @s,N@SortId int,@SortId
go