A表只有一个字段DD,如下:
GCCD 006CBC62 6227003819000230555 UW
GCCD 006CBC62 4367423811130846666 PS
GCCD 006CBC62 6227003812780056777 PS
GCCD 006CBC62 6227003812780056777 UU4条记录最后两条的卡号是一样的,我想让出来的数据只保留其中一条,如何实现??
GCCD 006CBC62 6227003819000230555 UW
GCCD 006CBC62 4367423811130846666 PS
GCCD 006CBC62 6227003812780056777 PSsubstring(dd,31,20)就是卡号这20位
GCCD 006CBC62 6227003819000230555 UW
GCCD 006CBC62 4367423811130846666 PS
GCCD 006CBC62 6227003812780056777 PS
GCCD 006CBC62 6227003812780056777 UU4条记录最后两条的卡号是一样的,我想让出来的数据只保留其中一条,如何实现??
GCCD 006CBC62 6227003819000230555 UW
GCCD 006CBC62 4367423811130846666 PS
GCCD 006CBC62 6227003812780056777 PSsubstring(dd,31,20)就是卡号这20位
insert into @tb select 'GCCD006CBC626227003812780056777PS'
insert into @tb select 'GCCD006CBC626227003812780056777UU'select * from @tb t where not exists(
select 1 from @tb where left(dd,len(dd)-2)=left(t.dd,len(t.dd)-2) and right(dd,2)<right(t.dd,2))GCCD006CBC626227003812780056777PS
select dd from A t
where not exists(select 1 from A where substring(dd,31,20)=substring(t.dd,31,20) and right(dd,len(dd)-51)<right(t.dd,len(t.dd)-51))
insert into @tb select 'GCCD006CBC626227003812780056777PS'
insert into @tb select 'GCCD006CBC626227003812780056777UU'
insert into @tb select 'GCCD006CBC626227003819000230555UW'
insert into @tb select 'GCCD006CBC624367423811130846666PS'
insert into @tb select 'GCCD006CBC624367423811130846666aa'
insert into @tb select 'GCCD006CBC624367423811130846666bb'select * from @tb t where not exists(
select 1 from @tb where left(dd,len(dd)-2)=left(t.dd,len(t.dd)-2) and right(dd,2)<right(t.dd,2))用一下看看,这只是举个例子
where not exists(select 1 from A where substring(dd,31,20)=substring(t.dd,31,20) and right(dd,len(dd)-51)<right(t.dd,len(t.dd)-51))字段是文本格式,跑出来提示:
服务器: 消息 8116,级别 16,状态 2,行 1
函数 len 的参数 1 的数据类型 text 无效。
服务器: 消息 8116,级别 16,状态 1,行 1
函数 right 的参数 1 的数据类型 text 无效。
服务器: 消息 8116,级别 16,状态 1,行 1
函数 len 的参数 1 的数据类型 text 无效。
服务器: 消息 8116,级别 16,状态 1,行 1
函数 right 的参数 1 的数据类型 text 无效。
服务器: 消息 8116,级别 16,状态 1,行 1
函数 len 的参数 1 的数据类型 text 无效。
服务器: 消息 8116,级别 16,状态 1,行 1
函数 right 的参数 1 的数据类型 text 无效。
服务器: 消息 8116,级别 16,状态 1,行 1
函数 len 的参数 1 的数据类型 text 无效。
服务器: 消息 8116,级别 16,状态 1,行 1
函数 right 的参数 1 的数据类型 text 无效。