Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003

    Unanswered: Date Format in SQL

    I have a question and any help would be greatly appreciated. I'm failry new to MS SQL, though i have been doing Access for sometime and am familiar with its SQL. I'm updating a database to MSSQL and am creating some views off of some old queries but the syntax has changed. Here is the Access SQL:

    PARAMETERS Month Short;
    SELECT tblrec.HCNumber, tblrec.LocationID, Sum(tblrec.Recvalue) AS RecValue, tblrec.use, tblrec.Unit, Format([Date],"m") AS Month
    FROM tblrec
    GROUP BY tblrec.HCNumber, tblrec.LocationID, tblrec.use, tblrec.Unit, Format([Date],"m")
    HAVING (((Format([Date],"m"))=Month([month])));

    The portion that I am having a problem with is the FORMAT statement to change the date column so it only displays the month (1-12) in the result pane. Any help would be greatly appreciated.


  2. #2
    Join Date
    Sep 2003
    format([date], "m") = datepart(month, current_timestamp)

  3. #3
    Join Date
    Feb 2002
    datepart(month, [date])

    Be very careful when using keywords as names for objects in sql - I strongly suggest not using keywords.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts