locked
How can i make this query work ? RRS feed

  • Question

  • User-1846805900 posted

    Hi

    Post Edited, please see Reply No4 to get full Details

    Thanks a lot 

    Thursday, October 22, 2015 6:34 AM

All replies

  • User2053451246 posted

    When you post complex SQL queries you want help with your table setup and sample data help us to provide a response.  If you follow what is in this article and spend some time to post a good question you will get good help faster.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Thursday, October 22, 2015 9:04 AM
  • User1644755831 posted

    Hello a.amin,

    Could you please provide a sample data for the query so we can reproduce this issue on our side?

    With Regards,

    Krunal Parekh

    Friday, October 23, 2015 1:37 AM
  • User-1846805900 posted

    Krunal Parekh

    Hello a.amin,

    Could you please provide a sample data for the query so we can reproduce this issue on our side?

    With Regards,

    Krunal Parekh

    Hi Krunal Parekh

    Hi ryanbesko

    so sorry for don't add data sample, this link is for script for sample data: http://www.mediafire.com/download/vrpj3q333ebhl62/Data.zip

    1. Table "AZTRH" >> has Invoice Header Data

    2. Table "AZTRD" >> has Invoice Details Data

    what i need from query is:

    1. get hours as rows (here hours is time of invoice from "AZTRH" Table >> Filed "EntryDate"):

    00
    
    01
    
    02
    
    03
    
    .....

    02. get count of invoice that has all items only from one "LOC_CD" >> one column where Loc_cd = 1 and other column where Loc_cd = 2 (this data is in table "AZTRD") - i can get all invoice that has only one "LOC_CD" on it from this query:

        SELECT 
           TR_NO 
        FROM AZTRD 
        WHERE 
           TR_TY = 102 AND
           LOC = 01 
        GROUP BY
           TR_NO 
        HAVING 
           MIN(LOC_CD) = MAX(LOC_CD)

    3. get count of invoices that has 2 items on it without any relate with "LOC_CD" - this data on AZTRD Tabel

    4. i need to get all data between two dates - i use date from AZTRH Table

    final result will be as example:

    Hours      Count_Invoice_Where_LOCCD_1      Count_Invoice_Where_LOCCD_2    Count_Invoice_Has_2_Items
    00 50 75 30
    01 70 100 12
    03 20 35 10

    Note: if that not possible hours can be columns and needed counts be as rows 

    Thanks a lot, and hope to get help soon

    Saturday, October 24, 2015 5:15 PM
  • User-1846805900 posted

    any updates ?

    Tuesday, October 27, 2015 4:06 PM
  • User-1846805900 posted

    Please any updates ?

    Tuesday, November 3, 2015 2:11 AM
  • User2053451246 posted

    Post your question as shown in the link I provided above and more people will be willing to help.

    Thursday, November 12, 2015 11:50 AM