declare @标志变量,@表变量 table (次序 int,标志 char(4),字段A char(4))
DECLARE Employee_Cursor CURSOR FOR
SELECT 标志 FROM 表 group by 标志
OPEN Employee_CursorFETCH NEXT FROM Employee_Cursor into @标志变量
WHILE @@FETCH_STATUS = 0
BEGIN
insert @表变量 select identity(1,1),标志,字段A from 表 where 标志=@标志变量
FETCH NEXT FROM Employee_Cursor into @标志变量
ENDCLOSE Employee_Cursor
DEALLOCATE Employee_Cursorselect * from @表变量 aaa
DECLARE Employee_Cursor CURSOR FOR
SELECT 标志 FROM 表 group by 标志
OPEN Employee_CursorFETCH NEXT FROM Employee_Cursor into @标志变量
WHILE @@FETCH_STATUS = 0
BEGIN
insert @表变量 select identity(1,1),标志,字段A from 表 where 标志=@标志变量
FETCH NEXT FROM Employee_Cursor into @标志变量
ENDCLOSE Employee_Cursor
DEALLOCATE Employee_Cursorselect * from @表变量 aaa
解决方案 »
- SQL2005以上有没有类似SQL2000企业管理器的 SQL语句格式化功能?(有图有真相)
- SQL2000注册问题
- 急...这个字段该如何更新?
- 请教 insert tabl select * from @Name 变量@Name 应如何表示
- 连接SYBASE服务器查询出错
- SQL下如何获取随机字符串
- insert into 里可以套多个select xxx from xx... 这样的语句吗,有完整的例子吗
- 求一段简单的SQL语句的写法
- 在SQL server组中建好2个注册服务器,如何在服务器1中用sql访问服务器2?
- sql2008 如何进入 超级用户
- 开发一数据库用binary存word文档和图片时它总是说“无法编辑该单元”,
- 老问题 to大力(前两个表的数量相加再减去第三个表的数量)
insert @a select 'J935', '新眼'
union all select 'J935', '染'
union all select 'J936', '新制'
union all select 'J936', '染'
union all select 'J937', '新眼'
union all select 'J937', '光'
union all select 'J937', '染色'
select (select count(*) from @a where code=a.code and type>=a.type) as cx,* from @a a order by code,cx cx code type
----------- ---------- ----------
1 J935 新眼
2 J935 染
1 J936 新制
2 J936 染
1 J937 新眼
2 J937 染色
3 J937 光
set @i=1
set @标志=''
select cast(0 as integer) 次序,标志,字段A into #tmp from tablename order by 标志
update #tmp
set @i=case when 标志=@标志 then @i+1 else 1 end,
@标志=case when COALESCE(@标志,'')=标志 then @标志 else 标志 end,
次序=@i
select * from #tmp
drop table #tmp
ALTER TABLE 表名
ADD 次序 <数据类型> [完整性约束]