drop table aa
go
create table aa
(
[name] nvarchar(20),
[language] nvarchar(20)
)
go
insert into aa([name],[language]) values ('张学友','zh');
insert into aa([name],[language]) values ('张学友','en');
insert into aa([name],[language]) values ('刘德华','zh');
insert into aa([name],[language]) values ('黎明','jp');
insert into aa([name],[language]) values ('刘德华','jp');
go
declare curaa cursor
for select [name],[language] from aa order by name,[language]
begin
declare @name nvarchar(20);
declare @language nvarchar(20);
declare @num decimal(18);
create table #aa([name] nvarchar(20),[language] nvarchar(20),cc decimal(18));
OPEN curaa;
fetch next from curaa into @name,@language;
if ((@name is not null) and (@language is not null))
insert into #aa(cc,[Name],[language])values(1,@name,@language);
WHILE (@@FETCH_STATUS <> -1)
begin
set @name = null;
set @language = null;
fetch next from curaa into @name,@language;
if ((@name is not null) and (@language is not null))
begin
select @num=Count(Name)+1 from #aa where Name=@name
insert into #aa(cc,[Name],[language])values(@num,@name,@language);
end
end
select * from #aa order by Name,[language];
drop table #aa;
CLOSE curaa;
DEALLOCATE curaa;
end