中藏网,现货原油分析师总监龙泽解盘,工作感想范文
我们可以通过下述方法删除重复记录:
例:表名:dbo.品种描述$,字段包括:id_pk,品种名称,性状标准编号,代码,首先创建一个和原表结构一样的表:
select * into tmpa from dbo.品种描述$ where 1=2--创建完毕
在数据表中,品种名称,性状标准编号这两个字段不能有重复值,执行下述脚本:
declare @varietyname nvarchar(255),
@stdcharcode nvarchar(255),
@icount int
set @icount=0;
declare insert_distinct_cursor cursor for
select 品种名称,性状标准编号 from dbo.品种描述$ group by 品种名称,性状标准编号
open insert_distinct_cursor
fetch next from insert_distinct_cursor into @varietyname,@stdcharcode
while (@@fetch_status <> -1)
begin
if (@@fetch_status <> -2)
begin
insert into dbo.tmpa (品种名称,性状标准编号,代码) select top 1 品种名称,性状标准编号,代码 from dbo.品种描述$ where 品种名称=@varietyname and 性状标准编号=@stdcharcode;
set @icount=@icount+1;
end
fetch next from insert_distinct_cursor into @varietyname,@stdcharcode
end
close insert_distinct_cursor
deallocate insert_distinct_cursor
print @icount
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
-
网友评论