Results 1 to 11 of 11

Thread: Issue in Query

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Issue in Query

    Dears,

    I m using the following Query which gives the required data
    SELECT Sale_Main.SaleDate, Sum(Sale_Detail.Qty) AS SumOfQty
    FROM Sale_Main INNER JOIN Sale_Detail ON Sale_Main.SaleId = Sale_Detail.SaleId
    GROUP BY Sale_Main.SaleDate, Sale_Detail.Qty


    But when i use it with SELECT Sale_Main.SaleDate, Sum(Sale_Detail.Qty) AS SumOfQty FROM Sale_Main INNER JOIN Sale_Detail ON Sale_Main.SaleId = Sale_Detail.SaleId GROUP BY Sale_Main.SaleDate, Sale_Detail.Qty
    HAVING (((Sale_Main.SaleDate)<[?]))
    it gives nothing... is something wronh in this Query ?? Please help

  2. #2
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Issue in Query

    What is the parameter value you are passing for [?] ?
    Last edited by Optional; Feb 1st, 2010 at 08:15 AM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Issue in Query

    Its a date i want to get data before 02/01/2010 or any date

  4. #4
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Issue in Query

    Does it not work as part of a join, like this ?:
    Code:
    SELECT
        Sale_Main.SaleDate,
        Sum(Sale_Detail.Qty) As SumOfQty
    From
        Sale_Main INNER JOIN Sale_Detail ON
            Sale_Main.SaleId = Sale_Detail.SaleId AND
            Sale_Main.SaleDate < [?]
    GROUP BY Sale_Main.SaleDate, Sale_Detail.Qty
    The HAVING statement filters the returned data from the GROUP BY statement.
    If the join works you don't need to get the data in the first place.
    Last edited by Optional; Feb 1st, 2010 at 08:21 AM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  5. #5
    gibra
    Guest

    Re: Issue in Query

    Quote Originally Posted by hafizfarooq View Post
    Dears,

    But when i use it with SELECT Sale_Main.SaleDate, Sum(Sale_Detail.Qty) AS SumOfQty FROM Sale_Main INNER JOIN Sale_Detail ON Sale_Main.SaleId = Sale_Detail.SaleId GROUP BY Sale_Main.SaleDate, Sale_Detail.Qty
    HAVING (((Sale_Main.SaleDate)<[?]))
    it gives nothing... is something wronh in this Query ?? Please help
    1. Database type ? SQL Server, Oracle, Access, ...

    2. show exactly the query string before to execute it, i.e.
    Code:
    dim sSQL As String
    sSQL = "SELECT Sale_Main.SaleDate, Sum(Sale_Detail.Qty) AS SumOfQty "
    sSQL = sSQL & " FROM Sale_Main INNER JOIN Sale_Detail "
    sSQL = sSQL & " ON Sale_Main.SaleId = Sale_Detail.SaleId "
    sSQL = sSQL & " GROUP BY Sale_Main.SaleDate, Sale_Detail.Qty"
    sSQL = sSQL & " HAVING (((Sale_Main.SaleDate) < " & <???>
    Debug.Print sSQL
    Show the result in Immediate window.

    Note tha the formatted string <???> is depend by 'database type' you use.



    P.S.
    Code must be formatted using Code button, not Bold style.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Issue in Query

    Dear Optional,
    Its giving Error "Joints expression not supported"

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Issue in Query

    Dear Gibra, still not showing anything

  8. #8
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Issue in Query

    Quote Originally Posted by hafizfarooq View Post
    Dear Optional,
    Its giving Error "Joints expression not supported"
    I though adding it to the join and removing it from having would work

    The only other thought I have is a maybe to try a sub-select:
    (If you are in MS-Access, it can be limited in SQL features)
    Code:
    SELECT SaleDate, SumOfQty FROM
        (SELECT
            Sale_Main.SaleDate,
            Sum(Sale_Detail.Qty) As SumOfQty
        From
            Sale_Main INNER JOIN Sale_Detail ON
                Sale_Main.SaleId = Sale_Detail.SaleId
        GROUP BY Sale_Main.SaleDate, Sale_Detail.Qty)
    Where
        SaleDate < [?]
    I'm not 100&#37; on the SQL syntax as I'm doing this without having access to Access or SQL 2008 at the moment.
    Last edited by Optional; Feb 1st, 2010 at 01:56 PM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  9. #9
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: Issue in Query

    OK, I was able to throw together a query similar to yours on my tables in access and I think your issue is not the syntax but the values you are comparing in the HAVING clause.

    Your Sale_Main.SaleDate column, I'm assuming is of date/time type thus you must be comparing it to a valid date value.

    You need to convert your parameter into a date value. That's propably why it doesn't find a match and returns empty data.

    In your query you need to use something like this:
    Code:
    HAVING (((Sale_Main.SaleDate)<DateValue([?])))
    check this link for some examples:
    How to store, calculate, and compare Date/Time data in Microsoft Access

    Hope this helped this time.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  10. #10
    gibra
    Guest

    Re: Issue in Query

    Quote Originally Posted by hafizfarooq View Post
    Dear Gibra, still not showing anything
    What?
    You haven't understand.
    Do nothing...

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Issue in Query

    Thread moved to 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width