Results 1 to 2 of 2

Thread: SQL??

  1. #1
    Join Date
    Dec 1969

    Default SQL??

    Hi,<BR> I have a drop down box in my asp page through which I can select the month and year for a particular report. <BR>The table has a column called last_updated_date which has dates like &#039;11/12/2000&#039; etc. my sql should filter the data based on this date. But I am not going to give full dates like this, but I am going to give just the month and year I select from the dropdown. for ex. if I select Jan 2000 from the drop down, my sql should pull all records that has the month of Jan and year of 2000 as the last updated date.<BR>how do I do that??

  2. #2
    Join Date
    Dec 1969

    Default What kind of DB???

    If either Access or SQL Server, the following should work:<BR><BR>SQL = "SELECT * FROM table WHERE Month(last_updated_date) = " & Request("MonthNumber") _<BR>&nbsp; &nbsp; &nbsp; &nbsp; & " AND Year(last_updated_date) = " & Request("YearNumber")<BR><BR>If you put the month and year into a single &#060;SELECT&#062;, do it like this:<BR><BR>&#060;SELECT Name="MonthYear"&#062;<BR>&#060;OPTION Value="1/2001"&#062; January 2001<BR>&#060;OPTION Value="2/2001"&#062; February 2001<BR>...<BR>&#060;/SELECT&#062;<BR><BR>and then take the MonthYear apart on the ASP page:<BR><BR>&#060;%<BR>MonthYear = Split( Request("MonthYear"), "/" )<BR>theMonth = MonthYear(0)<BR>theYear = MonthYear(1)<BR><BR>SQL = "SELECT * FROM table WHERE Month(last_updated_date) = " & theMonth _<BR>&nbsp; &nbsp; &nbsp; &nbsp; & " AND Year(last_updated_date) = " & theYear<BR>...<BR>%&#062;<BR>

Posting Permissions

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