Converting "row_number()" Query Into Access 2007 Format

Joined
Jul 6, 2011
Messages
1
Reaction score
0
Please help. I need to perform the fllowing in MS Access 2007

CREATE TABLE dbo.Foo
(
FieldA varchar(50) NOT NULL,
FieldB varchar(50) NOT NULL,
FieldC varchar(50) NOT NULL,
FieldD varchar(50) NOT NULL,
FieldE varchar(50) NOT NULL
)
go

insert into foo values('abc123', '123abc', '01', '01', '')
insert into foo values('abc123', '123abc', '012', '012', '')
insert into foo values('abc123', '123abc', '0123', '01', '')
insert into foo values('abc123', '123abc', '01234567', '01', '')
insert into foo values('abc123', '123abc', '012345', '012345', '')
insert into foo values('def123', '123def', '012345', '012345', '')
insert into foo values('def123', '123def', '', '012345', '')

select * from
(
select *, row_number() over(partition by fielda, fieldb order by len(fieldc) + len(fieldd) desc) seq
from foo
) ordered
where seq = 1;

The Idea is to resolve duplicate rows (based upon fields A & B) into single rows while directing which duplicate rows to toss out (i.e. keep the rows with longest entries in fields C & D), allowing field E to tag allong for the ride.

Results from the above should be 2 rows:
'abc123', '123abc', '012345', '012345', ''
'def123', '123def', '012345', '012345', ''


Thanks,

Mr Bill :confused:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top