SELECT Query Help

Hi All,

Hopefully someone can help me with this problem, here's the deal:

I have a table with order details in but it has some duplicated data
that I want to filter out (using a view). The raw data is like this:

Back Order Number       Order Number Short        Order Date
etc      etc
201201                         201201
01/01/01
201201/1                      201201
06/01/01
201201/2                      201201
10/01/01
200203/1                      200203
03/03/03

And I need to summarise this so I get a table with unique 'Order
Number Short' values but with the order date (and othe field data)
from the latest line. i.e. for the example above I would like to end
up with:

Order Number Short        Order Date         etc      etc
201201                           10/01/01
200203                           03/03/03

I hope this makes sense to you, hopefully someone can help.

Thanks in advance.

Alex
0
al
4/27/2010 2:06:13 PM
sqlserver.programming 1873 articles. 0 followers. Follow

2 Replies
475 Views

Similar Articles

[PageSpeed] 1

Try this:

SELECT back_order_number, order_number_short, order_date, <other_columns>,
FROM (
SELECT back_order_number, order_number_short, order_date, <other_columns>,
        ROW_NUMBER() OVER(PARTITION BY order_number_short ORDER BY order_date DESC) AS rk
FROM Orders) AS O
WHERE rk = 1;

-- 
Plamen Ratchev
http://www.SQLStudio.com
0
Plamen
4/27/2010 2:51:24 PM
Hi Plamen,

I think that gives me roughly what I need, many thanks for your help
and prompt reply.

Alex.


On 27 Apr, 15:51, Plamen Ratchev <Pla...@SQLStudio.com> wrote:
> Try this:
>
> SELECT back_order_number, order_number_short, order_date, <other_columns>=
,
> FROM (
> SELECT back_order_number, order_number_short, order_date, <other_columns>=
,
> =A0 =A0 =A0 =A0 ROW_NUMBER() OVER(PARTITION BY order_number_short ORDER B=
Y order_date DESC) AS rk
> FROM Orders) AS O
> WHERE rk =3D 1;
>
> --
> Plamen Ratchevhttp://www.SQLStudio.com

0
al
4/28/2010 7:38:17 AM
Reply:

Similar Artilces:

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

Query-based list w/1 Exception
I've created a query based distribtuion list which works fine yet out of the 1000 or so mailboxes it gives me I'd like to exclude 10. Is there a way? (Basically I have checked only "Users with Exchange mailbox") Make those 10 recipients members of a distribution group, and add the following to the query: (&(your current query)(!memberOf=distinguished Name of the distribution group)) Alternatively, if there's a common value of a particular attribute like location/city/department, et al, use that to exclude them. -- Bharat Suneja MVP - Exchange www.zenprise.com ...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

Go to special page in HTML help, how to change the left view in HTML help?
Hi, Made one .chm file. In a c++ program, launch the help file and go to the special page by HtmlHelp(NULL,"D:\Program files\file.chm::/help_internet.htm",HH_DISPLAY_TOPIC,0); It worked. The right window did display the help_internet.htm, but the left window, which has a lot of book icons in it, changed nothing. How to change the left view at the same time? Thank you, Best regards, Kelvin Kelvin, > Made one .chm file. > > In a c++ program, launch the help file and go to the special page by > HtmlHelp(NULL,"D:\Program > files\file.chm::/help_internet.htm...

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com &q...

simple query not working
Hi: Trying to set up a simple query, and can't figure out why its not working. Hope someone can help me think a little more clearly. Trying to link two tables: 1)tblServices, with fields 'ClientID#', 'DateofSvc', 'SvcCode' 2)tblCodes, with fields 'SvcCode', and 'SvcDescription' Join is 'SvcCode' Query design is to show ClientID, DateofSvc, SvcCode, and SvcDescription. SQL is "SELECT tblSERVICES.[ClientID#], tblSERVICES.DateofSvc, tblCodes.SvcCode, tblCodes.Description FROM tblSERVICES INNER JOIN tblCodes ON tblSERVICES.SvcCode = tblCodes...

Upgrade fails please help
I know this is in the wrong place, but I'm trying to get an upgrade to exchange 2k3 enterprise done today, as it's imperative.. I went through all the setup steps using the latest exchdeploy, I've read just about every KB and upgrade guide there is. Currently running 2K server standard w/ sp4, with exchange 2k standard. Two domain controllers, one PDC and a replication. DC1 and DC2,both running w2k server sp4. Ran the dcdiag and netdiag successfully, only one service that was not running gave an error. Ran forestprep and domainprep - no errors, at least any that were displaye...

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "GoBonnieGo" <GoB...

ListBox help
I have a list box that is populated from a query. There is a report that uses the selection from this list to pull data. The list contains the names of various employers. My questions is, is there a way to force the report to run based on all the employers listed? In other words I want the report to run each time for each employer listed. Thanks Nate Adding to this message: I am proficient in Java so I know if i wanted to do this in java the theory would look something like this. int i = 0; while(me.listbox.selected(i) = true) { DoCmd.SelectObject acReport, "Run_CFO_Report&qu...

HELP! can send email, but cannot receive
i am very new at this admin business. i have never done it before and i'm all alone at a small struggling cd distribution company. we are still running windows server 2000 with exchange (not sure exactly what version). i was informed this morning that the e-mail wasn't working. after running some tests i have come to the conclusion that internal sending and receiving of mail works fine. also, we can send e-mail out of the office, i tested it with my gmail account. however, we cannot receive e-mail. the amount of spam has decreased! as well as all our clients communication. i'm sor...

null value pass from form into query
For some reason I can't seem to get this to work and was hoping posting here would speed up finding the resolution. I have a form that the users a specifying a value from based on a list box. The users press a button on the form after doing the selection and it executes a query with criteria based on the value from the field; the query is using [Forms]![frmBatchesNeedingIndexing]![Contract].[Value] as the critera. This works fine when a users specifies a value. The problem I'm experiencing is I need this list box to have the capability to have a null value passed to the que...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

Link select with a blast
I have Win 7 Home Premium, x64. Quite often, when I select a link, a mouse pointer changes to a palm with a blast. I understand, the palm is the standard mouse pointer for link select, but what is the blast? What it indicates? -- Ilya Zeldes Fort Myers, Florida Hi Ilya, I suspect that this is being caused by a tracking program. Run something like Ad-Aware and see if it indicates a tracking company. If so, you can delete it, however, it might prevent you from accessing that particular website. Dave "Ilya Zeldes" wrote in message news:7A6FF9B1-5512-44...

Need help pulling data from cells in different workbooks
Hi, let me try and explain this the best I can: say i have a workbook with 2 pages, on the first sheet, in cells C27 C47, C67 and C87 on the Sheet2, I want to make a list. in that list contains data fro cells C27, C47, C67 and C87 from Sheet1 . on sheet2, the list wil look like: List ='Sheet1!C27 ='Sheet1!C47 ='Sheet1!C67 ='Sheet1!C87 Is there any easy way to pull that data without doing each lin individually. I know i can put in the = and pick the cell on the othe sheet, but I have 100's of cells I need to get data from. If i try an copy paste each line, it does...

Help with formula #18
I hope someone out there can help! I am not sure if a formula can be written for this. Here goes... I have numbers in columns C,D,E,F and G. I would like to write a formula that will do this - if the number in column C is an odd number, add 1, then if the number in column D is odd, add 1 again, and so on for E, F and G. So say three of the numbers in the five columns were odd, I should have three as my answer. Then I need to do the same but for even numbers. I have tried everything I can think of. :confused: -- yourproblemslvr ---------------------------------------------------------...

Select Case in a Change Event
Hi, I am trying to use a worksheet Change Event to trap changes to specific columns. depending on which column is chnaged by the user, the value in another ciolumn will be altered; so, changes in either column O or P will update column Q, changes in either column T or U will update column V and changes in column Z or AA will update column AB. What I can't figure out is the Select Case bit (where I've got the shouted question below). Here's what I've put together, any comments would be much appreciated. Private Sub Worksheet_Change(ByVal Target As Range) ...

!Help..... Generating xml from xml schema
Hi, I want to validate my xml file using xml schema and produce new xml file which confirms to that schema. I tried this using serializer() method. But this doesn't give me the complete solution. If i delete some elements in my xml schema, then the corresponding tags are deleted from my xml. But if i change my element name or add a new element, the changes are not getting reflected in the generated xml file. Can anyone help me to fix this. Thanks. ...

Select Records based another table...
This may be very elementary, but i can't wrap my brain around it. I have tried to dummy it down as much as i can for myself, with plans of adapting it into something working. I have three tables that look like the following: Tbl 1: ProdID A B C 1 $1 $2 $3 2 $4 $5 $6 3 $7 $8 $9 Tbl 2: RmNum ProdID 1 3 1 2 2 1 2 2 Tbl 3: RmNum Style 1 A 2 C Relationships are: [tbl1 ProdID] ------ [tbl2 ProdID] [tbl2 RmNum] ...

Help on formula
Greetings! I have the following columns: A. Cost B. Plan C. Additional D. Total $100.00 OTN $35 $135 OTN2 $40 $0 $150.00 OTN4 $25 $175 How can i get the TOTAL field to calculate Column A and C only when there is a value entered in Column A? In case you are wondering, the Additional Column (c) has assigned values, however I don't want a...

Anybody Help with previous question
Hi, I'm getting desperate to solve this, so my apologies for posting this again, but can anybody offer any help with this previous question. If the link doesn't work I have copied the orig question below. http://www.microsoft.com/office/community/en-us/default.mspx?pg=4&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.excel.misc&fltr=&mid=4044fba5-9f57-4be7-85a7-92ebb9093772 I have (been given) the code below that will add a row of 'jobs' to a worksheet named 'Database'. There isa check to see if these jobs have been already added a...

Controling queries displayed when clicking Load from Query button?
I want to be able to control the queries that are displayed when the Load from Query toolbar button is displayed. Can anyone tell me how the filter box list gets populated? Thanks. Paco ...

Multi-Select List Box Does Not Retain Selected Items
I created an Outlook Form in 2003. But when I select items in the list box they do not remain select when I select another control on the form. Any suggestions? Did you bind the list box to a keywords field? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "kaykay" <anonymous@discussions.microsoft.com> wrote in message news:276dd01c4638d$bd5af590$a501280a@phx.gbl... > I created an Outlook Form in 2003. But when I select > items i...