Order by problem.......how to Ascending order by date from the following query

hi
i have following query to show the monthly sales after summing up monthly sales total but i have facing a problem this query is not properly perform order by clause according to the months like jan,feb,mar etc... please tell me where i made mistake
SELECT     CashName AS AccountName, LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate) AS Months, SUM(Total) AS NetSales
FROM         dbo.CashSales
GROUP BY LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate), CashName

Select AccountName, Months, NetSales from
(SELECT CashName AS AccountName, LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate) AS Months, SUM(Total) AS NetSales,
DATEADD(month, DATEDIFF(month, 0, CashDate), 0) as dt
FROM dbo.CashSales
GROUP BY LEFT(DATENAME(month, CashDate), 3) + ' - ' + DATENAME(year, CashDate), CashName, DATEADD(month, DATEDIFF(month, 0, CashDate), 0)
t
Order By dt

Similar Messages

  • How to add a receipt number in the following Query for PO Report

    Hi Guys,
    I need a help regarding following query.
    Its a PO report for 11.5.10.2
    select distinct pv.segment1 supplier_number,
    pv.vendor_name supplier_name,
    pha.segment1 po_number,
    pha.revision_num revision_num,
    pha.authorization_status po_status,
    to_char(pha.creation_date, 'DD/MM/YYYY') creation_date,
    pha.currency_code currency_code,
    pla.sum_amount_ordered sum_amount_ordered,
    pda.sum_quantity_ordered sum_quantity_ordered,
    pda.sum_amount_received sum_amount_received,
    pda.sum_quantity_received sum_quantity_received,
    (pla.sum_amount_ordered - pda.sum_amount_received) sum_accrued, --AVI
    ( pda.sum_quantity_ordered - pda.sum_quantity_received) quantity_accrued, --AVi
    to_char(rsl.date_receipt, 'DD/MM/YYYY') date_receipt,
    -- rsl.receipt_num receipt_number,
    ppa.segment1 project_code, ppa.project_status_code, --10.0.0.4
    aia.invoice_num invoice_num,
    aia.invoice_date invoice_date, --AVI 
    aia.creation_date invoice_creation_date, --AVI 
    aia.amount invoice_amount_allocated_to_po, --AVI
    pla.purchase_basis,
    pla.category_id,
    -- pda.item_description,
    haou.name organisation, --10.0.0.3
    pda.sum_quantity_billed sum_quantity_billed , --10.0.0.3
    gcc1.CONCATENATED_SEGMENTS,
    gcc2.CONCATENATED_SEGMENTS
    from po_headers_all pha,
    po_vendors pv,
    pa_projects_all ppa,
    hr_all_organization_units haou,
    (select po_header_id,
    sum(quantity * unit_price) sum_amount_ordered,
    org_id,
    purchase_basis,
    category_id
    -- pla.item_description,
    from po_lines_all
    group by po_header_id, org_id
    , purchase_basis,
    category_id
    -- pla.item_description
    ) pla,
    (select pla.po_header_id,
    pda.project_id,
    sum(pda.quantity_ordered) sum_quantity_ordered,
    sum(pda.quantity_delivered * pla.unit_price) sum_amount_received,
    sum(pda.quantity_delivered) sum_quantity_received,
    sum(pda.quantity_billed) sum_quantity_billed, --10.0.0.3
    accrual_account_id
    from po_distributions_all pda, po_lines_all pla
    where pla.po_line_id = pda.po_line_id
    group by pla.po_header_id, pda.project_id,accrual_account_id
    ) pda,
    (select po_header_id, charge_account_id,
    -- rsh.receipt_num,
    min(rsl.creation_date) date_receipt
    from rcv_shipment_lines rsl
    where rsh.SHIPMENT_HEADER_ID=rsl.SHIPMENT_HEADER_ID
    group by po_header_id,charge_account_id
    ) rsl,
    (select distinct aia.invoice_num, pda.po_header_id , aia.invoice_date --10.0.0.3
    , aia.creation_date , sum(aida.amount) amount
    from po_distributions_all pda,
    ap_invoice_distributions_all aida,
    ap_invoices_all aia
    where pda.po_distribution_id = aida.po_distribution_id(+)
    and aia.invoice_id(+) = aida.invoice_id
    Group by
    aia.invoice_num, pda.po_header_id , aia.invoice_date --10.0.0.3
    , aia.creation_date) aia,
    (select haou2.organization_id, haou2.name
    from fnd_flex_value_sets ffvs,
    fnd_flex_value_norm_hierarchy ffvnh,
    fnd_flex_values_vl ffvv,
    hr_all_organization_units haou1,
    FND_FLEX_VALUE_CHILDREN_V ffvcv,
    hr_all_organization_units haou2
    where ffvs.FLEX_VALUE_SET_NAME = 'CAP_CODE_BU'
    and ffvs.FLEX_VALUE_SET_ID = ffvnh.flex_value_set_id
    and ffvnh.parent_flex_value like 'PO%'
    and ffvv.FLEX_VALUE_SET_ID = ffvnh.flex_value_set_id
    and ffvv.FLEX_VALUE between ffvnh.child_flex_value_low and ffvnh.child_flex_value_high
    and substr(haou1.name, 1, Instr(haou1.name, '-')) =
    substr(ffvv.DESCRIPTION, 1, Instr(ffvv.DESCRIPTION, '-'))
    and haou1.organization_id = fnd_global.org_id
    and ffvcv.parent_flex_value = ffvnh.parent_flex_value
    and ffvcv.flex_value_set_id = ffvs.flex_value_set_id
    and substr(haou2.name, 1, Instr(haou2.name, '-')) =
    substr(ffvcv.DESCRIPTION, 1, Instr(ffvcv.DESCRIPTION, '-'))
    union --10.0.0.1
    select f.organization_id, f.name --10.0.0.1
    from hr_all_organization_units f --10.0.0.1
    where f.organization_id = fnd_global.ORG_ID --10.0.0.1
    ) bu
    , po_line_locations_all plla --10.0.0.4
    , gl_code_combinations_kfv gcc1
    ,gl_code_combinations_kfv gcc2
    where pv.vendor_id = pha.vendor_id
    and pla.po_header_id = pha.po_header_id
    and pda.po_header_id = pha.po_header_id
    and pha.po_header_id = rsl.po_header_id(+)
    and pda.project_id = ppa.project_id(+)
    and pha.po_header_id = aia.po_header_id(+)
    and aia.po_header_id = pha.po_header_id
    and pla.org_id = haou.organization_id
    and pha.authorization_status in ('APPROVED', 'OPEN')
    and plla.po_header_id = pha.po_header_id --10.0.0.4
    and plla.closed_code in ('APPROVED', 'OPEN', 'CLOSED FOR INVOICE', 'CLOSED FOR RECEIVING', 'CANCELLED') --10.0.0.4
    and bu.organization_id = haou.organization_id
    AND gcc1.code_combination_id = pda.accrual_account_id
    AND gcc2.code_combination_id =rsl.CHARGE_ACCOUNT_ID
    In the following query I have commented receipt_num using the table rcv_transaction_headers.
    If I uncomment it the query results huge number of unexpected report.
    How can I add receipt number to the following query?
    Should I use rcv_transactions. If yes, what would be the join conditions.
    Kindly help as its urgent.
    Thanks in advance.
    Regards
    Avijit

    Sandeep is correct. I don't have time to tell you the correct query, but mine is something like this based on Sandeep's information:
    SELECT rsh.receipt_num
    FROM   rcv_transactions      rcvt,
           po_lines_all          pla,
           rcv_shipment_headers  rsh
    WHERE  rcvt.shipment_header_id   = rsh.shipment_header_id
    AND    rcvt.PO_LINE_ID          = pla.PO_LINE_ID
    AND    pla.item_id              = (select distinct inventory_item_id
    from mtl_system_items
    where segment1 = '1216107-2')

  • How do I get routing data from the Map App (powered by TomTom) so I can display the point-to-point annotations (turn-by-turn navigation) without leaving my own application.

    I have a tableView displaying a list of contacts from a Cloud Database.  After selecting a contact, I push to a programmatically created MKMapView.  Then I display the initial region (the view) that includes the users current location (starting point) and their selected destination (end point).
    Now I want to display annotations (as described in the Location Awareness Programming Guide) that displays polylines which will represent the turn-by-turn navigation IN MY OWN APPLICATION, and not in the Map App currently used in IOS6. 
    Due to licensing and its becoming depricated in IOS 6, I do not want to get routing data from the Google Maps API.  How do I get routing data from the IOS 6 Map App (powered by TomTom) so I can display the point-to-point annotations (turn-by-turn navigation) without leaving my own application?
    I checked out Stack Overflow and other forums which basically left me with the impression that this is not possible. I also checked out the TomTom iPhone Mobile SDK User Guide from the TomTom Developer Portal and am still confused.  It must be possible to retrieve routes, since the Map App can display turn-by-turn directions.  How can I retrieve turn-by-turn data that I may display as a route within my own application?

    Thanks Michael. Apologies for the slow reply I was away for a bit (holiday blitz at work and visiting family madness etc.etc.) back now, I set both options you requested to "never " and retried the CMS software with no change. 
    I do have progress of a sort though, as a test I took a separate test PC and put a clean install of Win7 on and loaded up the CMS software (it worked perfectly) and then took the version of ole32.dll off that machine and put it onto the computer I had built
    for her (using Linux) and...
    got a new error code. Darn I was so sure I had found a clever solution this time lol.
    Anyway now when the CMS fails it gives me a similar error but the offending module is "ntdll.dll" sooo... I tried taking the "working" version of ntdll.dll from the test box and moving it over (making sure to back up the existing ones
    first so I could put them back if needed) to her new PC and the PC would not boot. 
    It seems to want the original versions of a few Dynamic Link Libraries and if I could somehow give it those while not breaking Win7 it should theoretically work seeing as it no longer errors with ole32.dll. 
    ntdll.dll however seems necessary for Win7 to boot.
    So what I am wondering now is:
    Is there some way to have both versions of the DLL file in the system32 folder (bypassing the "cannot have two files with the exact same name in the same folder" thing) or rename the original DLL's something else and somehow make the CMS look for
    the new named versions so the system has the updated DLL's it needs to boot/run and the CMS has the old ones it wants to run or is there someway to have a self contained install of the CMS, say on a USB flash drive and give it it's own E:/windows/system32/needed
    dll's  path to the files it needs? 
    Willing to try any other options or settings you may have come up with as well.
    Thanks again for your reply and my apologies for not answering sooner.

  • How can delete my iphone5 data from the date its restored?

    how can delete my iphone5 data from the date its restored?

    it's unclear what you mean
    if you wish to remove your iphone5 data you connect it to iTunes on the computer and click the restore button and choose restore to factory defect

  • How do I recover Apps Data from the iCloud on iPhone 4S with IOS 6.1?

    How do I recover Apps Data from the iCloud on iPhone 4S with IOS 6.1?

    You would have to restore to your entire iCloud backup, if you have one.  (The backup includes app data.)  Restoring to an iCloud backup has to be done in the initial setup process.  If you have any data on your phone now that is not in the backup that you want to save you'll need to do that first.  Then go to Settings>General>Reset and tap Erase All Content and Settings.  You will then go through the setup screens as you did when the phone was new. When given the option, choose Restore from iCloud Backup.  Be sure you are connected to wifi and your charger as this will take some time to finish.

  • How can I restore my datas from the trash ( itunes music)?Thanks

    How ca I restore my datas from the trash( i-tunes) I still can read the lists, but they are not backed. Thks

    Try DataRescue from ProSoft.

  • HT1296 I bought my wife a new Ipad 3. How do I transfer her data from the old Ipad 1 to the new one?

    I bought my wife a new Ipad 3. How do I transfer her data from the old Ipad 1 to the new one?

    Sync the old one, and get a full back up stored.  Make sure you transfer your purchases to I tunes, and make sure you upload any photos taken on the pad, or imported thru the cck.
    Then plug the new pad in, and set it up from the backup of the old one.  In theory, all the stuff that was in the back up will migrate to the new pad.  If apps, music or books get lost, you can redownload them for free, using the same appLe id.  
    If you are selling or gifting the old one,   When you are done and happy with the new set up,  go to setting, general, reset, reset all content and data.  This will place the pad in factory new condition.   Lastly, if it is a 3 g pad, especially if it a Verizon pad, make sure to cancel the plan

  • How to print out a date from the past

    I am trying to print out a date from the past but I cant seem to get It,
    Lets use for example Independece Day,
    How would you write the code in order to print out that exact date?

    Look at the
    [url=http://java.sun.com/javase/6/docs/api/index.html?
    java/util/Date.html]Date APIActually the Calendar class would be better to use, since you can set all the different fields from year to second, plus things like day of week, day of month, week of year, etc.
    too slow
    Message was edited by:
    hunter9000

  • How do you get deleted data from the app Tote M'Notes back on iPad ????

    How do I get deleted data from app Tote M'Notes back???...Not displaying in my notebook anymore...also how do i retrieve data from apps stored in Icloud?

    Why don't you use the fully-qualified-domain-name (FQDN) of your GW and perform a re-direct to this ?
    This should be known (and everytime the same), addtionally you won't have any problems if there's any load balancer in between or in fron of the GWs.
    Secondly you'll have problems to get the IP -address if there's any proxy server involved.
    /ulf

  • Iphone4s water damage, phone is on but no network or wi fi. How can I download my data from the phone

    iphone4s has water damage but the has power but no network or blue tooth or wi fi is NOT working, how can get my data from the water damaged phone.

    Looks like the Wifi and network antenna has been damaged by the water. It is a hardware problem and can only be fixed by the professionals.

  • Apple just replaced a defective iPad. How do I restore my data from the cloud to my iPad?

    My iPad was replaced and would like to know, how do I restore my files from the cloud to my iPad?

    http://support.apple.com/kb/HT1766?viewlocale=en_US&locale=en_US
    Go to Settings>General>Reset and tap Erase All Content and Settings.  This will erase your device.  Then you will go through the setup screens again as you did when your device was new, and when given the option, select Restore from iCloud Backup.

  • How do I get my data from the icloud?

    I backed up my data to icloud then i got an entirely new iphone becaus eth eold one was faulty, so how do I get my old data that I put on the cloud onto my new phone? thanks fore any responses

    Open the following link http://support.apple.com/kb/HT4137, scroll down where it says "To restore your device using a previous backup", click on iCloud.

  • How do I report/analyze data from the KM activity reporting service

    I have turned on the km activity reporting service and I am getting .txt files generated with the information I am looking for but now I'm looking for the best way to collect this data from all the server clusters and aggregate the data for easier data analysis.  I have reviewed the 'how to analyze portal activity with the activity data collector' white paper.  This leads me to believe that the only way to collect and analyze this data is to write a script that collects and analyzes the data.  Is this true or is there a better way of gathering and reporting this data?  Is this data stored in a table somewhere?

    Hi,
    the portal only offers basic monitoring capabilities. But it offers the possibility to create quite extensive logs, like km activity reporting service. What the portal writes to a DB table are the PAR statistics. The quite more extensive KM and ADC data is written to a file.
    You can use SolMan to analyze the data. SolMan can gather, analze and write the data into the BI and gives you the basic report.
    In the same way, you can use SolMan to gather the data and create your own BI reports. As it can be really hard to collect X logs from Y servernodes, SolMan offers an easy way to collect the different logs.
    br,
    Tobias

  • How to determine most recent date from the date column of internal table

    Dear friends
    would you like to tell me. how i determine the most recently changed record by looking at date and time from internal table i am not supposed to sort the table by date and time... I must check date and time with other records date and time to determine which record is most recently changed...
    here the scenario is.
    id idnumber chdate chtime
    1 123456 20060606 135312
    2 123456 20060606 135900
    3 123456 20060606 132300
    4 123457 20060606 140000
    5 123457 20060606 142500
    in the above scenario i must keep in my mind that the most recently changed record is identical to its idnumber i can say that:
    the record should be fetched this way
    id idnumber chdate chtime
    3 123456 20060606 132300
    5 123457 20060606 142500
    because here the id 3 is the most recently changed in the idnumber 123456
    where id 5 is the most recently changed in the idnumber 123457
    please help me to determin how i am supposed to carry out this task any suggestion, code will be great help of mine.
    regards
    Naim

    After testing my suggestion above, I realized that it doesn't work because the delete adjacent actually will keep the first one and delete the rest.  I'm working with Srinivas's code a bit now,  I think it is almost what you want.  I am under the impression that you dont' want to HIGHest date/time, but just the last record of the sequence, if this is the case, then this code will help.  Here we will assign an index to each record per the idnumber, that way we can sort it and get the lastest record.
    report zrich_0001.
    types: begin of itab_type,
            id       type i,
            idnumber type i,
            chdate   like sy-datum,
            chtime   like sy-uzeit.
    types: end of itab_type.
    types: begin of itab_type2,
            id       type i,
            idnumber type i,
            index    type i,
            chdate   like sy-datum,
            chtime   like sy-uzeit.
    types: end of itab_type2.
    data: itab     type table of itab_type with header line,
          itab2    type table of itab_type2 with header line,
          prev_rec type itab_type.
    data: v_id type i.
    start-of-selection.
      itab-id       = 1.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135312'.
      append itab. clear itab.
      itab-id       = 2.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135900'.
      append itab. clear itab.
      itab-id       = 3.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '142500'.
      append itab. clear itab.
      itab-id       = 4.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '140000'.
      append itab. clear itab.
      itab-id       = 5.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '120000'.
      append itab.
      clear itab.
    <b>  data: counter type i.
    * Assign an index to each row per idnumber
      loop at itab.
        on change of itab-idnumber.
        if sy-tabix > 1.
          clear counter.
          endif.
        endon.
        clear itab2.
        move-corresponding itab to itab2.
        counter = counter + 1.
        itab2-index = counter.
        append itab2.
      endloop.
    * Sort it and get rid of older records.
      sort itab2  by idnumber ascending
                     index descending.
      delete adjacent duplicates from itab2 comparing idnumber.</b>
      read table itab2 with key idnumber = '123456'.
      write:/ itab2-chdate, itab2-chtime.
      read table itab2 with key idnumber = '123457'.
      write:/ itab2-chdate, itab2-chtime.
    Regards,
    Rich Heilman

  • After my recent update, excel did not save my latest copy.  it retrieved a copy from over a month ago.  How do i get my data from the last 4 weeks back?

    Yesterday, I updated my computer.  I have a excel document that I use everyday for work and saved the document prior to doing such.  After updating, I had to restart the computer.  Now when I open that excel document, it brings me back to a copy of the program I created over 4 weeks ago.  How do I get the most recent copy which had over 4 weeks of work in it?
    Thanks

    Good morning Gandrin
    There is quite a difference between syncing and back-up and they are different features in iTunes, although some people combine them together.
    1.  The first thing that happens when you connect your device is that a photo manager asks if you want to offload your photos.  I always do this because it is the most valuable way to back-up your photos only.
    2.  Then Itunes will come up and if you have automatic sync turned on it will begin to sync FROM your computer to your device.  It's a one-way sync and is the primary way to keep photos, music and some apps managed on your device.   New apps are synced onto your Itunes app tab. If you add or delete items in your iTunes folders then those changes are synced to your device.  I always check to make sure my new apps are now in my iTunes library and specific device tab.
    4.  There is also a back-up step where you can back your device onto your computer.  I think this is the step that should have been done when you got your new PC.  It doesn't save the apps here but does save their setting and data. I prefer to set this up to be a manual back-up process.
    http://support.apple.com/kb/HT4946.
    5.  There is also a a "Automatically sync new apps checkbox in your itunes device apps tabs.  That should be checked "on".
    6.  If the missing apps were purchased through iTunes then I think you can download them again (make sure you use the same Apple Id).  If you then resync with itunes those apps should appear in iTunes for you.
    Maybe there is something in my rambling that will help

Maybe you are looking for

  • HELP! (Please) How can I get my playlists previously created on my iPhone 4 back?

    Hi there. I have an iPhone 4, equipped with all of my music from my iTunes library on my MacBook Pro laptop. I often create playlists on my phone (when it is not plugged into the computer). When I went to plug my phone into the laptop to sync some ne

  • LCD Projector

    Use a projector frequently for presentations and am new to the Mac. Used to be able to toggle the projector and computer displays on and off with the F7 key. Anything like that on the MacBook Pro?

  • Not able to restart weblogic server

    Hi Guys, I have installed OIM 10g 6 months ago in my personal system and it is working fine till yesterday. Today, when I try to start the weblogic server, i am getting the below error and the command window getting closed immediately. Weblogic was i

  • Brand New iMac randomly shuts off!! Help!!

    I have no idea why this is happening. I've been using macs for 5 years now, had every generation iMac and not a single problem. My new Penryn chipset iMac 20" randomly shuts off!!! Why is this happening? Possibly a power supply issue? I've cleared th

  • What type of battery is in the DROID MINI?

    I know it is a 2000 mAh Li-ion. But I'd like to know what model it is?