set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER       proc [dbo].[movesitetree]
@moduleid int=0,               /*要移动的模块ID号*/
@movetype int=0                /*移动方式0为下移,1为上移*/
as
SET NOCOUNT ON/*-----这一句很重要哦:)),不然它只会认 insert #change......这个数据集:))*/
declare @sql nvarchar(4000), --声明动态sql执行语句
@pre_id int, --上一条记录ID
@next_id int, --下一条记录ID
@recordno int, --记录条数
@recordno2 int, --记录条数2
@checker int --比较数值
begin 
create table #change (id int)
create table #change2 (id int)
--附值
set @checker = 1 --checker附值为1
set @pre_id = dbo.module_pre_id(@moduleid)
set @next_id = dbo.module_next_id(@moduleid)
/*********--移动--*********/
if (@checker=@movetype) --如果向上移
  begin
    if (0!=@pre_id)
      begin
        truncate table #change--清空表
        truncate table #change2--清空表2
        select @recordno=count(*) from dbo.module_thisallid(@pre_id)--上条及子记录数
        insert #change (id) select id from dbo.module_thisallid(@moduleid)--本条包函记录的ID号
        select @recordno2=count(*) from dbo.module_thisallid(@moduleid)--本条及子记录数
        insert #change2 (id) select id from dbo.module_thisallid(@pre_id)--上条包函记录的ID号
        update Manage_Site set Sequence=Sequence-@recordno where id in (select id from #change)--本条上移
        update Manage_Site set Sequence=Sequence+@recordno2 where id in (select id from #change2)--上条下移
    end
  end
else --如果向下移
  begin
    if (0!=@next_id)
      begin
        truncate table #change--清空表
        truncate table #change2--清空表2
        select @recordno=count(*) from dbo.module_thisallid(@next_id)--下条及子记录数
        insert #change (id) select id from dbo.module_thisallid(@moduleid)--本条包函记录的ID号
        select @recordno2=count(*) from dbo.module_thisallid(@moduleid)--本条及子记录数
        insert #change2 (id) select id from dbo.module_thisallid(@next_id)--下条包函记录的ID号
        update Manage_Site set Sequence=Sequence+@recordno where id in (select id from #change)--本条下移
        update Manage_Site set Sequence=Sequence-@recordno2 where id in (select id from #change2)--下条上移
    end
end
drop table #change
drop table #change2
--------------------------------------------------------------------------------------------------------
end各位能给说一下这个存储过程是干什么用的,以及怎么使用
最好有每一条语句的详细说明

解决方案 »

  1.   

    '有数据库支持的话!试试:' exec movesitetree
      

  2.   

    @moduleid int=0, /*要移动的模块ID号*/
    @movetype int=0 /*移动方式0为下移,1为上移*/
    这两是需要传的
      

  3.   

    查看一下SQL语句里的参数引用嘛,这个就相当于其他语言程序中的方法/过程/函数/接口等的参数呀,
    例如C#中定义一个方法
    PROTECTED VOID GetABC(string str1,sting str2)
    {
     以下是对传入参数的计算(操作);
    }