PC Review


Reply
Thread Tools Rate Thread

Converting "row_number()" Query Into Access 2007 Format

 
 
New Member
Mr Bill's Avatar
Join Date: Jul 2011
Posts: 1
 
      6th Jul 2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Text "00:00:00:00" to time format in Access 2007 Martin Prunty Microsoft Access 5 2nd Apr 2010 07:51 AM
In Access 2007 what is format "Double"? AuroraGreen Microsoft Access External Data 2 20th Mar 2010 01:34 PM
Converting this "French" currency format to "English"? StargateFanNotAtHome Microsoft Excel Discussion 5 29th Jul 2009 02:01 PM
why does access 2007 convert "Like" to "Alike" in my query? Charlie Bamford Microsoft Access 1 23rd Apr 2008 02:28 PM
Converting "yyyymmdd" date string into "dd monthname yyyy" format stainless Microsoft C# .NET 2 31st Jan 2008 06:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 AM.