Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic queries

Status
Not open for further replies.

alvinmcg

Technical User
Oct 21, 2003
24
0
0
US
I have some queries which are based on the prior month. How can I setup my query to ask me to enter data or can this be automated to select the prior calendar month?

alvinmcg
 
You can try something like this:

Var
StartDate,
EndDate, Date
EndVar

StartDate.view("Enter start date:"); prompt user to enter criterion for start date
EndDate.view("Enter end date:"); prompt user to enter criterion for end date

:ALIAS_NAME:TABLE_NAME.DB | StartDate | EndDate |
| >=~StartDate,<=~EndDate |; passes values to the fields in query

EndQuery

Regards,

Almir
 
Here is some code I came up with that I attached to a pushbutton to run a query of last months data.
Note a little funny business to get the start of a day at 7:00 am instead of 12:01 am with the time however you should get the idea from the date handling. The basic idea came from The DB community web site.

I hope this helps.
Big D

Var
d0 Date
myQBE query
StartOfMonth Number
LastMonth Number
DaysLastMonth Number
Start Number
StartofLastMonth Number
FormVar Form
endVar

method pushButton(var eventInfo Event)
d0=today()
StartOfMonth=day(d0)-1.29166666-1
LastMonth=month(d0)-1
Start=StartOfMonth
Switch
case LastMonth=1:DaysLastMonth=31
case LastMonth=2:DaysLastMonth=28
case LastMonth=3:DaysLastMonth=31
case LastMonth=4:DaysLastMonth=30
case LastMonth=5:DaysLastMonth=31
case LastMonth=6:DaysLastMonth=30
case LastMonth=7:DaysLastMonth=31
case LastMonth=8:DaysLastMonth=30
case LastMonth=9:DaysLastMonth=30
case LastMonth=10:DaysLastMonth=31
case LastMonth=11:DaysLastMonth=30
case LastMonth=12:DaysLastMonth=31
case LastMonth=0:DaysLastMonth=31
endswitch

StartOfLastMonth=day(d0)-1.29166666

myQBE=Query
&quot;:pM6ReelReports:pM6ReelReports&quot; |DATE|GRADE NUMBER| RUN TIME|ELAPSED TIME| PRODUCTION TONS|REEL SPEED|REEL LENGTH|AVERAGE SHEET WIDTH|RDWT CD SPREAD|RCAL CD SPREAD|TOTAL BREAKS|TOTAL BREAK TIME|
|Check>TODAY-(~StartofMonth+~DaysLastMonth+1), <TODAY-(~StartOfMonth+1) | Check| Check|Check|Check|Check|Check|Check|Check|Check|Check|Check|



endquery

if not executeQBE(myQBE) then errorShow()
endif
FormVar.Open(&quot;:Global_Forms_800_X_600:pM6ProductionLastMonth.fdl&quot;)
endMethod
 
bigandfat,

You know, I think there might be a better way to return the number of days in the previous month. While I'm sure your code currently works, it seems, well, a bit imprecise.

Here's how I might approach that problem:

Code:
method run(var eventInfo Event)
var
   dt    Date
   siMM,
   siYY,
   siDD  SmallInt
endVar

   ; Get First Day of this month
   dt = today()
   siMM = dt.month()
   siYY = dt.year()
   dt = Date( string( siMM ) + &quot;/01/&quot; +
              string( siYY ) )

   ; Go to last day of last month and then calc days
   dt = dt - 1
   siMonthDays = dt.DaysInMonth()

   ; Show Results
   msgInfo( &quot;FYI&quot;, &quot;Last month ended on &quot; + String( dt ) +
                   &quot; and had &quot; + String( siMonthDays ) + &quot; days.&quot; )


endMethod

It's looks at the problem a bit differently, but should return an accurate count of days. You can certainly extend this in any number of ways.

For example, you could return the current day in the previous month with this:

Code:
method run(var eventInfo Event)
var
   dt    Date
   siMM,
   siYY,
   siDD  SmallInt
endVar

   ; Get First Day of this month
   dt = today()
   siMM = dt.month()
   siYY = dt.year()
   siDD = dt.day()
   dt = Date( string( siMM ) + &quot;/01/&quot; +
              string( siYY ) )

   ; Calculate the same day in the previous month
   ; by returning the last day of the previous month
   ; and then using that to determine the month and
   ; year needed for the final date.

   dt = dt - 1
   siMM = dt.month()
   siYY = dt.year()
   dt = Date( string( siMM ) + &quot;/&quot; +
              string( siDD ) + &quot;/&quot; + 
              string( siYY ) )

   siMonthDays = dt.DaysInMonth()

   ; Show Results
   msgInfo( &quot;FYI&quot;, &quot;Last month was &quot; + String( dt ) +
                   &quot; and had &quot; + String( siMonthDays ) + &quot; days.&quot; )


endMethod

As usual, Paradox provideds different ways to do things and it sometimes helps to know these different approaches, so you can choose the one appropriate for your current situation.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top