Results 1 to 2 of 2

Thread: Extracting parts of a date

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    11
    I have a database and I want to create a SQL statement within VB to extract only the dates in a particular field which have a specific month.

    Any ideas?

    Thanks in advance

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    This is the query I generated using the Northwind database in SQL 7, the key here is using the Month function and the Year function. If you database has these functions, you should be all set

    This will get the total number of monthly orders, the month, the year, and the total amount of freight shipped in that month. The month I have specified is #7 (July)

    SELECT COUNT(*) AS OrderCount, MONTH(orderdate) AS TheMonth,
    YEAR(orderdate) AS TheYear, SUM(freight)
    AS TotalMonthlyFreight
    FROM Orders
    WHERE MONTH(orderdate) = 7
    GROUP BY YEAR(orderdate), MONTH(orderdate)

    Enjoy

    Tom

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