Sql query Q.

Results 1 to 2 of 2

Thread: Sql query Q.

  1. #1
    Join Date
    Dec 1969

    Default Sql query Q.

    I have a case where i will have 2 dates. I need to pick up my records from the database grouped according to the months that fall between the two dates.<BR>So if I have 9/1/2000 and 9/15/2001, then my records will be displayed like <BR>Sep 2000 ---data---- <BR>Oct 2000 ---data----<BR> and so on till<BR>Aug 2001 ----data----<BR>Sep 2001 ----data---- (though only till 15 Sep 2001)<BR><BR>This is what I have done :<BR><BR>date1="9/1/2000"<BR>date2="9/15/2001"<BR>day1=day(date1)<BR>day2=day(date2)<BR>mon 1=month(date1)<BR>mon2=month(date2)<BR>yr1=year(da te1)<BR>yr2=year(date2)<BR><BR>for i=yr1 to yr2<BR><BR>if i=yr1 and yr1&#060;&#062;yr2 then <BR> stmon=mon1<BR> endmon=12<BR> <BR>elseif i=yr1 and i=yr2 then<BR> stmon=mon1<BR> endmon=mon2<BR><BR>elseif i=yr2 and yr1&#060;&#062;yr2 then<BR> stmon=1 <BR> endmon=mon2<BR>else<BR> stmon=1<BR> endmon=12<BR>end if<BR> <BR>for j=stmon to endmon<BR> stday=1<BR> endday=""<BR>if yr1=i and mon1=j then stday=day1<BR>if yr2=i and mon2=j then endday=day2<BR>if endday="" then<BR> if (j=1)or (j=3)or (j=5)or (j=7)or (j=8)or (j=10)or (j=12)then endday=31<BR><BR> if (j=4)or (j=6)or (j=9)or (j=11) then endday=30<BR> if (j=2) then<BR> if (i mod 4=0) and (i mod 400=0) then <BR> endday=29<BR> else<BR> endday=28<BR> end if <BR> end if<BR>end if<BR> <BR>d1=j&"/"&stday&"/"&i<BR>d2=j&"/"&endday&"/"&i<BR><BR>&#039; at this point, im running my sql query.<BR><BR>next<BR>next<BR><BR>SO the jist of it is that i am creating the dates myself to suit the criteria and then picking up the records.<BR>This is working all right.... no probelms at all. But the important Q again... is there any better (neater) way of doing this? <BR><BR>Thanx<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Sql query Q.

    To improve performance it may be possible to retrieven al lthe data you want from the database first with one query, ordered by the date.<BR><BR>Then you can loop through the recordset and check in what month you are. If the month changes from one record to the next, you know you can start a new row of data.<BR><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