-
May 31st, 2018, 01:06 AM
#1
Thread Starter
Member
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.
-
May 31st, 2018, 02:09 AM
#2
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.
-
May 31st, 2018, 02:32 AM
#3
Thread Starter
Member
Re: Counting data from Database with Filtering The date
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))
-
May 31st, 2018, 02:48 AM
#4
Re: Counting data from Database with Filtering The date
So the issue is indeed that there's no GROUP BY clause there.
-
May 31st, 2018, 03:47 AM
#5
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)"
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
Tags for this Thread
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
|