Results 1 to 5 of 5

Thread: Counting data from Database with Filtering The date

  1. #1

    Thread Starter
    Member gbfai87's Avatar
    Join Date
    Oct 2017
    Posts
    33

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member gbfai87's Avatar
    Join Date
    Oct 2017
    Posts
    33

    Re: Counting data from Database with Filtering The date

    Quote Originally Posted by jmcilhinney View Post
    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))

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Counting data from Database with Filtering The date

    So the issue is indeed that there's no GROUP BY clause there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    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
  •  



Click Here to Expand Forum to Full Width