I am using Excel VBA do write a SQL query using ADO.
E.g. of my query:
Select Item,Sum(BookValue) From ItemLedger Group By Item
How do I modify my query such that those items with Sum(BookValue)=0 will not be retrieved?
I am using Excel VBA do write a SQL query using ADO.
E.g. of my query:
Select Item,Sum(BookValue) From ItemLedger Group By Item
How do I modify my query such that those items with Sum(BookValue)=0 will not be retrieved?
Last edited by NBVC; 05-06-2011 at 03:51 PM.
Include a HAVING option in your SQL statement.
Cheers,
Last edited by ConneXionLost; 05-10-2010 at 01:50 AM.
Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.
I have tried
Select Item,Sum(BookValue) From ItemLedger Having Sum(BookValue)<>0 Group By Item
But it returns an error.
This example SQL statement works:
If the same structure doesn't work for you, then perhaps it is the VBA you're using to run it.Please Login or Register to view this content.
Last edited by ConneXionLost; 05-10-2010 at 02:08 AM.
Assuming you don't have negative BookValues, why not just add a:
WHERE BookValue > 0
clause?
Please Login or Register to view this content.
Remember what the dormouse said
Feed your head
Hi guys,
Thanks for your help. I've got it working. I didn't know sequence of the syntax makes a difference and that GROUP BY must be before HAVING.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks