Counting data from Database with Filtering The date
Is there any query in VB.net that can I use to solve my problem.
I have TblIDExpiry and Column IDExpiryDate.
and I have 12 Labels named January to December in the form.
example, I want to count all data that will expire in January and display it on a Label.
My code isn't working, only counting all data in table.
Re: Counting data from Database with Filtering The date
How can we know what's wrong with your code without seeing it? This seems like a SQL question anyway, so it would belong in the Database Development forum rather than VB. It seems like you should be grouping by month and then aggregating by count. If you are doing this in SQL, you might consider following the SQL tutorial link in my signature below, which should include information on grouping.
Re: Counting data from Database with Filtering The date
Quote:
Originally Posted by
jmcilhinney
How can we know what's wrong with your code without seeing it? This seems like a SQL question anyway, so it would belong in the Database Development forum rather than VB. It seems like you should be grouping by month and then aggregating by count. If you are doing this in SQL, you might consider following the SQL tutorial link in my signature below, which should include information on grouping.
Sorry, Im Ussing Ms. Access as Database, heres my code.
Select Count(*) from TblEmployee where str(datepart("yyyy",ExpDate)) +'/'+ str(datepart("m",ExpDate))
Re: Counting data from Database with Filtering The date
So the issue is indeed that there's no GROUP BY clause there.
Re: Counting data from Database with Filtering The date
Not just that, your Where clause is wrong. A where clause has to equate to a Boolean (true or false), yours equates to a date.
Should "str(datepart("yyyy",ExpDate)) +'/'+ str(datepart("m",ExpDate))" actually be your Group By? If so you don't need to do the string conversion, you can just use "Group By datepart("yyyy",ExpDate), datepart("m",ExpDate)"