I run a web design firm, and we also sell hosting on a yearly basis to our customers. I'm writing a Ruby script to read all of the customers from a MySQL database and check to see if a year has passed. If it has (or is at least close to expiring), I want it to send an Email to them.
I have the Emailing part down, but how would I check to see if one year has passed using the Time class, or another solution based in SQL?
(looking back with this edit, it seems as though I don't quite know the SQL needed, so any help on that is appreciated)
If you really want to solve this issue using ruby you can use >> when dealing with a Date to increment it by N months (such as 11, which will give your customers some time to deal with the payment).
When you've got this incremented date you should compare it to what the current date is to see if it's less or equal (ie. the date is in the past), if so; send out your email.
>> (Date.strptime('2012-07-07') >> 11).to_s
=> "2013-06-07"
>> if (Date.strptime('2011-06-15') >> 11) < DateTime.now
>> print "More than 11 months has passed!"
>> end
More than 11 months has passed!=> nil
Though, you are much better of solving this issue directly in the SQL query, which would boil down to something as the below:
SELECT field1, field2, ..., fieldN
FROM `customers_table`
WHERE ADDDATE(last_payment, INTERVAL 11 MONTHS) <= NOW ()
Related
My query name:
Total Daily Orders Summary
My Input [2 columns]:
business_date,# Daily Orders
I need these 3 columns as calculated output:
Orders# (7 days) Average, Orders# (30 Days) Average ,Orders# (Acuum Average) [i.e.from day one to date]
I have tried my best to find clear answers for how to do moving/rolling average in Microsoft Access query but unfortunately, I couldn't make it work for me. Therefore, I have decided to put my request here to see if someone will put me in the right direction to start working on my files and tasks.
I have trouble with correlated subqueries myself. here is a VBA/Access solution that I think is easier.
Start by adding a code module to your Database by clicking create on the menu and selecting module -which is all the way to the right.
Then create a public function like:
Public Function AverageOrders(CurrentDate As Date, NumberofPriorDays As Integer) As Integer
AverageOrders = DSum("DailyOrders", "MyTable", "business_date BETWEEN #" & CurrentDate & "# AND #" & DateAdd("d", -NumberofPriorDays, CurrentDate) & "#")
End Function
we create the function this way so access intellisense works. This is a powerful technique which I also use to wrap any calls to access form parameters. To find the function in a query right click on the top of a query column and choose build. In the build wizard under expression elements select functions then your database. Average Orders and any other public functions you make will appear. Or just type it.
then you get:
February has 28 days. We don't use # for DateOrders because In strings # denotes a date. To get the accumulated average just pick an absurdly early date or make another function without [NumberofPriorDays].
I'm building a query to determine how many workdays have been completed. I've already figured out the opposite, which is for days remaining. The queries are identical save for the > and < operators, yet the < operator does not work with the "wpdatatables" plugin I'm using. I know I may need to speak with their support about it but I figured I'd ask in case anyone has a clue:
SELECT count(calendar.date) AS Workday FROM calendar
WHERE calendar.is_weekday = 1 AND calendar.is_holiday != 1
AND year(calendar.date) = year (curdate())
AND month(calendar.date) = month (curdate()) AND day(calendar.date) <= day(curdate())
Seems simple enough, but the plugin keeps giving me an error saying it's not finding any data, whereas both queries work just fine in Sequel Pro. Do you think it could just be the plugin? Or perhaps there's another way to build the query.
I have an MS-Access DB that pulls information in from an Excel file with 6 worksheets, so I get 6 tables. I created 7 queries, all of which make tables from the excel data, 6 of those 7 do a count of an item ie:
SELECT DISTINCT DISPLAYNAME, COUNT(DISPLAYNAME)
FROM [TXFR REC]
GROUP BY DISPLAYNAME
The 7th query pulls those 6 tables together into a sort of report table by using left joins onto one of the tables, where the connection to all the others is a DISPLAYNAME.
I have created a Form with 4 buttons and two date boxes, a start date and an end date. What I want to do is the following:
Choose Start Date
Choose End Date
Press Button that runs the 7 queries in the order I specified by invoking the date range from steps 1 and 2 ** THIS IS WHERE I AM STUCK: I do not know how to force this date range on the queries **
Run the report
Export the report
Close the form
The date boxes are set to General Date and the method used for them is GetDates so you just click in the box and the calendar pops up and you choose your date.
I did see this post here but am not following to well:
Date Range Form
Here is the text from a test query as suggested by a user and in the format suggested by the answering person:
SELECT [NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME, Count([NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME) AS CountOfPHYSICIANDISPLAYNAME INTO NO_ADMIT_DX_COUNT
FROM [NO ADMITTING DX (HEALTH ISSUE)]
WHERE ((([NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME) Is Not Null) And (([NO ADMITTING DX (HEALTH ISSUE)].AdmitDtm) Between Forms!PRINT_REPORT![START DATE] And FORMS!PRINT_REPORT![END DATE]))
GROUP BY [NO ADMITTING DX (HEALTH ISSUE)].PHYSICIANDISPLAYNAME;
** This query now works properly **
Thank you for all the help.
For your query, use something like this.
SELECT DISPLAYNAME, COUNT(DISPLAYNAME)
FROM [TXFR REC]
WHERE [TXFR REC].yourDate BETWEEN [Forms]![yourFormName]![yourStartDate]
AND [Forms]![yourFormName]![yourEndDateField]
GROUP BY DISPLAYNAME
All of your queries that you want to rely on a date range should have these parameters. The advantage to doing it this way is that you can give your two date fields on your form a datePicker. It would still work the same if you did something like this:
SELECT DISPLAYNAME, COUNT(DISPLAYNAME)
FROM [TXFR REC]
WHERE [TXFR REC].yourDate BETWEEN [Please Enter a Start Date]
AND [Please Enter an Ending Date]
GROUP BY DISPLAYNAME
It's all preference though. Just throw a button on there and go to Misc in the wizard and choose run query if you want.
Edit your queries to rely on the value of the form in the where clause:
[Forms]![form's name]![form's control]
Here's a Screenshot example
This will make your queries only work with the form, however. You might consider copying your queries and renaming and editing the copies to reflect its limitation.
Scenario:
I have a lookup table which has a date column, I need to look at this date column and check if its today's date, if not then wait for 5 mins and check the same thing again, and if the date is current send an email and exit the loop, and if after 6 retries if the date is not current execute a SQL task.
I have a ForLoop Container with the following settings:
InitExpression : #[User::Counter] = 0
EvalExpression : #[User::Counter] < 6
AssignExpression : #[User::Counter] = #[User::Counter] + 1
How / Where do I check the date :
SELECT ControlTimeStamp from LOOKUPTABLE
WHERE ControlTimeStamp = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
Note:
I'm using Business Intelligence Development Studio (BIDS) 2008 for SSIS package development.
I think you'll want an approach like this. Execute your SQL Task to determine whether today is your date. From there you'll need to either sleep for N minutes or you'll want to send an email. The trick is to use an Expression on the Precedence Constraint between the Execute SQL Task the children.
My implementation differs slightly from what yours but the concept remains the same. I created two variables, #ActualDate and #ReferenceDate. #ActualDate is today and #ReferenceDate gets set from the Execute SQL Task. I then see whether they are equivalent. For what you have, if you get a result, then you know the send mail condition has been met so change your Expressions to meet that.
What isn't shown is how to terminate the loop early as I'm not quite certain how to do that.
i have a deployment to do within 2 days time and for the last three days i have been busy trying to understand this one thing am stuck in. It probably might be very silly of me but please take me as a newbie.
I am using an opensource software php opensource pos and it is made on CI. Now the issue is that the reports in the application are different than what my client wants. I want to change that to the way they want it but i cant.
this is the code:
$this->db->select('sale_date, sum(total) as total, sum(profit) as profit');
$this->db->from('sales_items_temp');
if ($inputs['sale_type'] == 'sales')
{
$this->db->where('quantity_purchased > 0');
}
elseif ($inputs['sale_type'] == 'returns')
{
$this->db->where('quantity_purchased < 0');
}
$this->db->group_by('sale_date');
$this->db->having('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"');
$this->db->order_by('sale_date');
return $this->db->get()->result_array();
every thing is working fine and as expected. Now i need to make some changes but the issue is i cannot find the temp database to see which fields it has. This database table (the temp one) is being used in all the reports functions, same database.
Can some one be so helpful and explain me the way it works, or how is that i can make a change to it!?
The scenario is that it is giving a summary of all the sales in the selected date range as total. I want a break down in terms of cash, credit, credit card, debit card etc.
I have another report which shows that, but not in date wise as in not saying how much in which day but in total of the date range. This one gives the total as in total sales in a day but not the break up of it as in what was what.
You can login here first:
https://demo.phppointofsale.com/index.php/login (id and password is saved on the page)
Then you can paste this link on the address bar and see the report.
https://demo.phppointofsale.com/index.php/reports/summary_sales/1969-12-31/2012-03-13/all/0
I need it to be a breakdown of the total and remove the tax, profit and subtotal columns and change that with the kind of payment as in cash | credit | cheque etc and then a total for that day.
PS: I am sorry for such a big writing but i am really stuck, please help me out. Thank you in advance.
The table name is sales_items_temp.
To see the actual database config (for database name, host, etc), look in either /system/application/config/database.php or /application/config/database.php depending on the version of Codeigniter.
To see about changing the query, check out http://codeigniter.com/user_guide/database/active_record.html.