日期:2014-05-17  浏览次数:20586 次

求一存储过程 哪位高手路过看看
图一     排序              图二      排序
    -------------------         -------------------
       1    设置                   1      设置
       4    设置                   2      设置
       8    设置                   3      设置
      12    设置                   4      设置

以上两图为某页面的部分  写一存储过程实现 由图一转为图二的样子 数值 1 4 8 12 都在文本框里 通过设置按钮可以修改 不论改为多少 点设置后刷新变为图二,要求用存储过程来实现;

简单一些就是求一可以排序 排为1、2、3、4……的存储过程脚本

可设置一下一些参数
CREATE Procedure [dbo].spWageItemSetSort
(
@W_I_Id varchar(50),
                  @Sort Int,
@result varchar(50) out -- 返回结果
)

--DECLARE @NW_I_Id varchar(50) --工资项目ID
--DECLARE @OldSort int          --原排序值
--DECLARE @MaxSort int --当前最大的排序值

------最佳解决方案--------------------
--查询
--sql 2000
select 图二 = (select count(1) from tb where 排序 = t.排序 and 图一 < t.图一) + 1 , 排序 from tb t
select 图二 = (select count(1) from tb where 图一 < t.图一) + 1 , 排序 from tb t

--sql 2005
select 图二 = row_number() over(partition by 排序 order by 图一), 排序 from tb t
select 图二 = row_number() over(order by 图一), 排序 from tb t

--更改
update tb
set 图二 = (select count(1) from tb where 排序 = t.排序 and 图一 < t.图一) + 1 , 排序 from tb t

------其他解决方案--------------------
if not object_id('tb') is null
drop table tb
Go
Create table tb([ID] int,[name] nvarchar(2))
Insert tb
select 1,N'设置' union all
select 4,N'设置' union all
select 8,N'设置' union all
select 12,N'设置'
Go
--2000
Select ID=(select count(*) from tb where id<=t.id),
       [Name] 
from tb t
---2005
select ID=row_number()over(order by id ),
       [name]
from tb

------其他解决方案--------------------


if object_id('tb')>0
drop table tb
create table tb(id int,s