|
-
Feb 1st, 2010, 07:35 AM
#1
Thread Starter
Fanatic Member
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
-
Feb 1st, 2010, 08:06 AM
#2
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
-
Feb 1st, 2010, 08:07 AM
#3
Thread Starter
Fanatic Member
Re: Issue in Query
Its a date i want to get data before 02/01/2010 or any date
-
Feb 1st, 2010, 08:15 AM
#4
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
-
Feb 1st, 2010, 08:16 AM
#5
Re: Issue in Query
 Originally Posted by hafizfarooq
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.
-
Feb 1st, 2010, 08:21 AM
#6
Thread Starter
Fanatic Member
Re: Issue in Query
Dear Optional,
Its giving Error "Joints expression not supported"
-
Feb 1st, 2010, 08:28 AM
#7
Thread Starter
Fanatic Member
Re: Issue in Query
Dear Gibra, still not showing anything
-
Feb 1st, 2010, 08:32 AM
#8
Re: Issue in Query
 Originally Posted by hafizfarooq
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% 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
-
Feb 1st, 2010, 08:45 AM
#9
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
-
Feb 1st, 2010, 01:48 PM
#10
-
Feb 1st, 2010, 05:22 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|