Query based on dates to show what has not been done - ms-access

I am trying to make sure communication gets sent out properly.
I have a list of emails in EmailMain that need to be sent to my team leaders a certain number of days before the team arrives.
I want to make a reminder list or possibly a conditional formatting that will alert me that I need to send more emails.
I know that the query I included below is not right. I just added it as a starting point.
Tables Involved.
EmailLog
EmailLogID
EmailMainID
EmailDate
TeamDetailsID
EmailMain
EmailMainID
EmailSubject
AdvanceDays
TeamDetails
TeamDetailsID
ArriveDate
SELECT EmailMain.EmailMainID, EmailMain.AdvanceDays, EmailLog.SentDate, EmailLog.TeamDetailsID, TeamDetails.ArriveDate
FROM TeamDetails INNER JOIN (EmailMain RIGHT JOIN EmailLog ON EmailMain.EmailMainID = EmailLog.EmailMainID) ON TeamDetails.TeamDetailsID = EmailLog.TeamDetailsID
WHERE (((EmailLog.TeamDetailsID)=39))
ORDER BY EmailMain.AdvanceDays DESC;

Related

Get All Tickets in OSticket

Can someone help me figure out how I can retrieve all tickets? I read online and saw that there's no API to do this yet? I also read that i can write some sql code to retrieve them?
My objective is: Check OSticket to see if the ticket with the same subject is created more than 3 times, then to basically alert me ( for now it can just be a message in Powershell that says it, as I'm scripting in PS).
For that I need to retrieve all tickets in the OSticketDB. Since I just have it locally for now, I have a sql DB setup but I don't see something along the lines of ost_tickets? Not sure how I can retrieve tickets that have been duplicates from same subject.
I'm not sure I understand your question correctly. But here is SQL query, that will return all tickets, where subject has occurred more than 3 times.
SELECT
cdata.ticket_id,
cdata.subject,
ticket.number,
subjectstable.subjectcount
FROM
osticketdb.ost_ticket AS ticket
INNER JOIN osticketdb.ost_ticket__cdata AS cdata ON ticket.ticket_id = cdata.ticket_id
INNER JOIN
(SELECT subject, COUNT(*) as subjectcount FROM osticketdb.ost_ticket__cdata GROUP BY subject) AS subjectstable
ON subjectstable.subject = cdata.subject
WHERE subjectstable.subjectcount > 3

MySql query to retrieve a conversation between 2 users

I'm having a quick issue I could use an opinion on. I'm attempting to write a MySQL query that pulls all the messages from a conversation that is exclusively between two users.
I need to be able to pull messages sent by 'user1' that are sent to 'user2', and messages sent by 'user2' that are sent to 'user1'.
I've dabbled a bit and I've currently got the 4 conditions needed for my query to execute (see below). I've been trying to work out what way to structure it to get the specific data I need though.
SELECT privatemessage_message, privatemessage_time_created, privatemessage_sent_by, privatemessage_sent_to
FROM tbl_privatemessages
WHERE privatemessage_sent_by = 1
OR privatemessage_sent_by = 2
OR privatemessage_sent_to = 1
OR privatemessage_sent_to = 2
ORDER BY privatemessage_time_created ASC
For context :
This is going to be used within a PHP MySQL website with AJAX being used for the private messaging. I'm fine withthem sides of it, but this particular SQL query is a nuisance.
Any help is greatly appreciated :)
You need to use AND to combine the sender and recipient, and OR to combine the different directions.
SELECT privatemessage_message, privatemessage_time_created, privatemessage_sent_by, privatemessage_sent_to
FROM tbl_privatemessages
WHERE (privatemessage_sent_by = 1 AND privatemessage_sent_to = 2)
OR (privatemessage_sent_to = 1 AND privatemessage_sent_by = 2)
ORDER BY privatemessage_time_created ASC

Filtering SQL tables

I am trying to set up an sms appointment reminder for client appointments. I use the cms opemEMR. But there do not seem to be a appointment reminder function installed, and no extentions for that function. So I thought it will be possible to do that by filtering out the appointment from SQLi using PHP, and then set up a cron job.
I am new to php and mySQL, and I have been re-thinking how to do it so many times, that by head spins, so I hope some one can show me the right direction.
Here is how I think it can be done:
First I need to go to the calendar table that holds all the calendar events(1), and find the client appointments(2). Then I need to filter the appointments, that scheduled between 24 - 25 hours in advanced(3) (I will then tell the cron job to run every hour).
Then I will need to grab the client id(4) and the time of the appointment.
I will now have client ids on all client, I need to send reminders to.
Second I need to go to the patient data table(5), to grab the phone number(6) from the client ids(7) I just extracted.
I guess, I can then put this data in to another table, from where I can fetch it when running my sms-reminder.
This is a way, I believe would work, but I am no sure how to do it. Hope some one can show me.
Hope it makes sense and that the images help.
Reg.
Lars
Check this query:
SELECT e.pc_pid, e.pc_eventDate, e.pc_startTime,p.phone_cell FROM opememr_postcalendar_events e
LEFT JOIN patient_data p ON p.id = e.pc_pid
WHERE e.pc_Title = 'Office Visit' AND e.pc_eventDate BETWEEN DATE( DATE_SUB( NOW() , INTERVAL 1 DAY ) ) AND DATE ( NOW() )
ORDER BY e.pc_eventDate, e.pc_startTime;

Access 'No Records Found' when Records Exist

I have a form in Access 2010 that's used as a search form to filter records matching specific criteria.
I transferred information in the backend from one set of tables to another. Now, the filter doesn't work. Even if I leave all the criteria blank - ie. set it to bring up all records - it tells me, 'No records found.'
I've remapped the tables a few times, made sure they all have information, and are linking and opening properly. What could be preventing Access from finding the records?
Here's the filter query, if it helps any. It doesn't appear to be filtering properly, even though it works fine with the old tables.
SELECT Activity.*, ActivityCash.*, EngSchDates.*, Monitoring.*, Procurement.*,
LookupDistrict.*
FROM ((((Activity LEFT JOIN LookupDistrict ON Activity.District =
LookupDistrict.District) INNER JOIN ActivityCash ON Activity.GWP = ActivityCash.GWP)
INNER JOIN EngSchDates ON Activity.GWP = EngSchDates.GWP)
INNER JOIN Procurement ON Activity.GWP = Procurement.GWP) INNER JOIN Monitoring ON
Activity.GWP = Monitoring.GWP ORDER BY Activity.District,
Activity.[ProgramYear], [Activity].GWP;
In general, to debug these types of problems, try removing one table at a time from the FROM clause (and SELECT) until you get your results back.
Remove AND [Activity].[Designer] like '*' from the query.

To Get The Date difference

Hi iam having two columns
PR_PurchaseRequestHistory
1)uid
2)POUID
3)PRUID
4)PRDUID
5)CreatedDtTm
6)ModifiedDtTM
PO_PurchaseOrderDetails
1)uid
2)PRUid
3)RespondedDtTm
4)ModifiedDtTm
5)CreatedDtTm
(unique PRUId) is assigned for every new request and the order is placed POUId for that PRUId.I need to get average date difference for the ID's generated for Particular months
I thinks this makes issue clear
Please help me out. I have been struck in this issue for long time
SELECT AVG(HOUR(TIMEDIFF(PO_PurchaseOrderDetails.RespondedDtTm, PR_PurchaseRequestHistory.CreatedDtTm)))
FROM PR_PurchaseRequestHistory
INNER JOIN PO_PurchaseOrderDetails ON PR_PurchaseRequestHistory.PRUID = PO_PurchaseOrderDetails.PRUID
WHERE MONTH(PR_PurchaseRequestHistory.CreatedDtTm) = 3 -- March
AND YEAR(PR_PurchaseRequestHistory.CreatedDtTm) = 2011