表结构:ID NAME
A 张三
B 李四
C 王五比如我指定移动一行,结果变为
ID NAME
A 李四
B 王五
C 张三如果指定移动两行,结果为
ID NAME
A 王五
B 张三
C 李四依此类推。
A 张三
B 李四
C 王五比如我指定移动一行,结果变为
ID NAME
A 李四
B 王五
C 张三如果指定移动两行,结果为
ID NAME
A 王五
B 张三
C 李四依此类推。
解决方案 »
- 如何恢复analysis services 数据库
- 这类问题怎么解决最好?
- 表已删除, 可syscolumns里还能找到此表的字段
- 使用rollup,group by的問題
- XP操作系统SQL2005始终不能链接1433端口,数据库服务已经启动,防火墙都关闭了也不行?
- 如何用alter table将原有的一列加上标识identity(1,1)
- 请问本机sql server 服务为什么无法启动?
- select语句分组汇总的问题
- 高手们,请问哪位知道怎么把ACCESS的自动编号清零?
- 请问:想让几列的组合唯一怎么设?
- QQ群召集爱学程序的人,汇编,数据结构,数据库,计算机组成
- 用BCP 命令导出数据到EXCEL 文件,发现身份证号或日期的格式问题?
set @i = 1select NAME from #test where id1 > @i
union all
select NAME from #test where id1 <= @i
set @i = 1
select id1=identity(int,1,1) , name into #test1 from
(
select NAME from #test where id1 > @i
union all
select NAME from #test where id1 <= @i
) aselect a.id , b.name from #test a,#test b where a.id1 = b.id1
set @i = 1
select id1=identity(int,1,1) , name into #test1 from
(
select NAME from #test where id1 > @i
union all
select NAME from #test where id1 <= @i
) aselect a.id , b.name from #test a,#test1(前面那个这里错了.) b where a.id1 = b.id1
insert @ta
select 'A', '李四' union all
select 'B', '王五' union all
select 'C', '张三'begin TRANSACTION
select *,r_id=identity(int,1,1) into # from @ta
select id=(select id from # where r_id=a.r_id-1),name=(select [name] from # where r_id=a.r_id-1) from # a
ROLLBACK TRANSACTION(所影响的行数为 3 行)
(所影响的行数为 3 行)id name
---------- --------------------
NULL NULL
A 李四
B 王五(所影响的行数为 3 行)
insert into tabletest
select 'A','张三'
union all select 'B','李四'
union all select 'C','王五'select identity(int,1,1) new_id,*
into newtable
from tabletestcreate proc up_moverow(@name varchar(10),@rows int)
as
declare @oldname varchar(10)
declare @row_id int
declare @new_id int
select @new_id =new_id from newtable where name=@name
select @row_id = (select new_id from newtable where name=@name)+@rows
select @oldname = name from newtable where new_id=@row_idupdate newtable
set name=@name
from newtable
where new_id=@row_idupdate newtable
set name=@oldname
from newtable
where new_id=@new_iddrop table newtable,tabletest--正数向下移动,负数向上移动
exec up_moverow '王五',-2