114la导航源码:如何在PB的数据窗口中不显示重复的记录,例如按身份证号显示全部不重复的记录.(不要以身份证号建立主键)

来源:百度文库 编辑:高考问答 时间:2024/04/26 04:26:30
具体的实现是在数据窗口中实现,还是在PB的窗口中实现,如何实现?
非常感谢两位的回答,离解决问题就差一点了,用 select distinct 身份证号 from (表名),看到的表就只有身份证号这个字段,如果把身份证号变成*或者在身份证号后面加字段,那么身份证号就有重复的了,请问各位大侠如何解决?小弟一定尽己所能追加分数.

可以先把不重复的生成到一个新表中不就行了,你可以参考下面的语句
--exec up_distinct 'a_dist','id','name'
if exists (select * from sysobjects where objectproperty(object_id('up_distinct'), 'IsProcedure') = 1)
drop procedure up_distinct
GO

create procedure up_distinct(@t_name varchar(30),@f_key varchar(30),@f_name varchar(30))
--f_key表示是分组字段,即主键字段
as
begin
declare @max integer,@id varchar(30) ,@name varchar(30) ,@sql varchar(7999)-- ,@type integer
select @sql = 'declare cur_rows cursor for select '+@f_key+','+@f_name+' ,count(*) from ' +@t_name +' group by ' +@f_key+','+@f_name +' having count(*) > 1'
exec(@sql)
open cur_rows
fetch cur_rows into @id,@name,@max
while @@fetch_status=0
begin
select @max = @max -1
set rowcount @max
/*elect @type = xtype from syscolumns where id=object_id(@t_name) and name=@f_key
if @type=56 */
select @sql = 'delete from '+@t_name+' where ' + @f_key+' = '+ @id --+' and ' + @f_name +' = '+ @name
/*if @type=167
select @sql = 'delete from '+@t_name+' where ' + @f_key+' = '+''''+ @id +'''' */
exec(@sql)
fetch cur_rows into @id,@name,@max
end
close cur_rows
deallocate cur_rows
set rowcount 0
end
这是存储过程!

 select * from (表名)

在程序里定义一个变量让它等于身份证号
var aa

if(身份证号=aa)
{转到下一条记录;}
else
{aa=身份证号;
处理;
转到下一条记录;}

因为同一个身份证好就是有许多组数据,你又要显示其它的的字段,他当然就给你展示出来了,不然的话岂不是没有完成你的select任务。他不会聪明到知道你具体要某一个身份证好的那一组数据啊,是把