trick SQL to read data as true instead of false - sql

I have searched everywhere online before asking this:
I'm self-teaching how to build a report that makes it easier for my co-workers. I wanted to pull a report for the clients that never attended. We use last_bill_svc_date, but the problem is I have been facing was that there is a certain visit type that is non-billable due to the client being a self-pay.
Is there a way for me to trick SQL into thinking that a visit type is true for a billable service date?
I'm using two different tables and I am hoping that is all I needed in order to pull a never attended report. I have 17 visit type ID number that I need it to be true for billable at all time.
I'm using Custom AD Hoc provided by Credible for Electronic Health Records "Query builder 2.0" is what I use.
Any help is greatly appreciated and I will clarify as best as I can. It is my goal to show the last billable service date to be null so I can count how many members that have not attended the centers yet.
EDIT
I'm not entirely sure how to show an example, but I'll do my best.
client_id first_name last_name last_bill_svc_date
--------------------------------------------------
1 A-firstname A-lastname Null
2 B-firstname B-lastname Null
3 C-firstname C-lastname Null
4 D-firstname D-lastname Null
5 E-firstname E-lastname Null
6 F-firstname F-lastname Null
7 G-firstname G-lastname Null
8 H-firstname H-lastname Null
9 I-firstname I-lastname Null
I actually was able to pull the exact record above, but it ignores the one with self-paying visit type.
I once used WHERE statement as in
Where (ClientVisit.visittype_id In ('514', '519', '527', '533', '509',
'500', '528', '540', '529', '511', '506', '513', '545', '530', '510', '512',
'507') And Clients.client_status = 'active')
The visit type is the one I wanted it to focus on, but it, unfortunately, focus on billable visit type and ignores the non-billable. I wanted to be able to force SQL to read the specific visit type to be billable no matter what. I struggle to figure out which column I need to gather info from since Credible's custom AD HOC has 11 pages worth of tables. As of now, I'm using two tables: Clients and ClientVisit
EDIT Part Two
Select Clients.client_id As client_id,
Clients.last_name,
Clients.first_name,
Clients.last_bill_svc_date
From Clients
Where Clients.client_id In (Select ClientVisit.client_id
From ClientVisit) And Clients.client_status = 'active'
This is the code I currently have on the list with a help of a friend. It showed a result of 47 members that have not attended to one of the centers. In the spreadsheet, I just showed BLANK result for last_bill_svc_date.
I did a report coming from "Advanced Search Report" that was provided in Credible where I select the encounter types that I know it is billable. While I know sticking with advanced search report is probably the best way to go. The reason for me to switching over to Export Tool where I can run the report from SQL Query Builder 2.0 because I will be able to have it showed the client's primary team only instead of doing it manually when I go through the Advanced Search Report.
The Result I want to see is as follows:
Client's first and last name,
Client's start date (So, we know how long member has been an active member and still haven't attended)
last billable service date (I'll filter it to be NULL),
Primary Team (Each client is only allowed to have one primary team, but they can be assigned to multiple teams).
I realized that visit id number 528 has a lot of self-pay, which forced the visit type to be non-billable in Credible. That's when I want to force it to read it as if ID '528' is billable even though it claims that it is non-billable.
Another reason for wanting to specify the visit type because we provide billable phone services where we can do outreach to clients. Clearly, that doesn't count as client's attendance to one of the centers.
It has to be something so simple to get it working the way I want to see. Otherwise, I'll have to accept and continue using Advanced Search Report feature.

Related

Filtering access control data to get list of people inside office

I would like to create an SQL query for a "Role Call" which would show me the people who are inside the building only. Each person has his own access card and has to go in or out of the building using 1 of 4 turnstiles. So far I managed to retrieve the 4 turnstiles (in and out) data for todays date. I need to filter the list to only show people who had an "in" entry but did not leave yet. People can come and go as they please and use any of the 4 turnstiles and have multiple "ins" and "outs" per day.
I am bit stuck here how to do this.
I am joining 2 tables which have the device information (turnstiles) and the log of all swiped cards. I am filtering for the turnstiles data only and todays date.
SELECT [dbo].[lACLog].[LogID],[dbo].[lACLog].[LogDate],[dbo].[lACLog].[DeviceAddress],[dbo].[pPeriphery].[Name],[dbo].[pPeriphery].[PeripheryUID],
[dbo].[lACLog].[CardNr],[dbo].[lACLog].[Name],[dbo].[lACLog].[PersonalNr],[dbo].[lACLog].[PersID]
FROM [dbo].[lACLog]
LEFT JOIN [dbo].[pPeriphery]
ON [dbo].[lACLog].[DeviceAddress]=[dbo].[pPeriphery].[DeviceAddress]
WHERE [dbo].[lACLog].[LogDate]>=CAST(GETDATE()AS Date) AND [dbo].[pPeriphery].[PeripheryUID]
IN ('2130B72E-D8E9-4269-B6B0-68BEC95CB483',
'9229D4B6-5CD7-43E6-B7C7-BF9779333521',
'919C5D57-5885-460A-8679-D0C257837D82',
'C45B8C65-FF46-42FA-B428-E01853DEB65E',
'550669EC-2BC4-4008-A1A7-469E9C5266C5',
'3C843DFA-CFE3-4E01-93E9-ADE50A2D5BED',
'FB6736AA-2940-497F-A367-5BB0308F4B77',
'E6EE768E-1587-41EF-B7FD-B61A14BA9395');

MS Access - Report to only show items that are out of date/or soon to be

Context:
Due to the remote nature of working, the team I work in each have a laptop that they're using for their role (we have thinkpad displaylink units when in the office to connect the laptop to screens). I am working to improve the current allocation records file, which was just a big spreadsheet that you just added a new user to the bottom row. It was messy and hard to read at times, so i've decided to move the data into MS Access and created my data entry and user lookup form, which are working perfectly and make the job easier. I have also been able to make a number of reports that will come in handy too (who has what model ect).
Query:
Now the issue is, each of the laptops have a warranty and I am able to produce reports which lists the users and their warranty due date, but this will show all the warranty dates, whether they've been passed or in the future. I want to be able to produce 2 report/queries, the first that will just bring up the laptops who have a warranty that have expired, then another one to bring up those who will expire within the next 6 months so that we can make relevant decisions.
If anyone can assist with this, it will be welcome.
Apply filter criteria to report when opening. Either have parameters in report RecordSource or use code (VBA or macro) to build criteria for OpenReport method WHERE CONDITION argument. Expressions for criteria (ExpireDate is field, substitute with your field name):
[ExpireDate] <= Date();
[ExpireDate] BETWEEN Date() AND DateAdd("m", 6, Date())

Users updating same row at the same time SQL Server

I want to create a SQL Server table that has a Department and a Maximum Capacity columns (assume 10 for this scenario). When users add them selves to a department the system will check the current assignment count (assume 9 for this scenario) in the department and compare it to the maximum value. If it is below the maximum, they will be added.
The issue is this: what if two users submit at the same time and the when the code retrieves the current assignment count it will be 9 for both. One user updates the row sooner so now its 10 but the other user has already retrieved the previous value before the update (9) and so both are valid when compared and we end up with 11 users in the department.
Is this even possible and how can one solve it?
The answer to your problem lies in understanding "Database Concurrency" and then choosing the correct solution to your specific scenario.
It too large a topic to cover in a single SO answer so I would recommend doing some reading and coming back with specific questions.
However in simple form you either block the assignments out to the first person who tries to obtain them (pessimistic locking), or you throw an error after someone tries to assign over the limit (optimistic locking).
In the pessimistic case you then need ways to unblock them if the user fails to complete the transaction e.g. a timeout. A bit like on a ticket booking website it says "These tickets are being held for you for the next 10 minutes, you must complete your booking within that time else you may lose them".
And when you're down to the last few positions you are going to be turning everyone after the first away... no other way around it if you require this level of locking. (Well you could then create a waiting list, but that's another issue in itself).

SQL - Need to find a way to check whether a member has renewed

So, this is probably simple. I need to find a way to check whether a member of a scheme has renewed their membership or let it expire, I need to generate a simple list of those whom have not renewed.... There are complicating factors however, in that I cant use Excel, and it can only be a single step to Crystal reports (though I have solved the issue in Excel using a simple Countifs and if Formula)
Now for the problem.
The membership has specified Start/End Dates in separate columns in the table. It is easy to see whether this, in a row basis has expired. The issue is that if they have renewed, this is logged as a separate table entry linked by a Individual reference to the member. There are also multiple Qualifications I also need to test against.
So, whilst I can test the expiration date, the question is how can I test against the rest of the data, based on whether the Individual Reference and Qualification name and then check whether this is "Current". Doing this would enable me to therefore test whether the Membership has therefore been renewed, or not, on an individual line.
Any advice on methods would be appreciated.
Without knowing what data you have and making assumptions out the wazoo, try something along these lines
select distinct Member_id,
case
when exists (select 1
from members m2
where m2.member_id = m1.member_id
and (m2.expiry_date is null
or m2.expiry_date > '2018-01-25'))
then 'Active'
else 'Expired'
end as mem_status
from members m1
What the exists does is look and see if that member has an active status

hiding unnecessary fields in Access Report

At my workplace there is a "Daily Feedback" database where details are entered of any errors made by Customer Service Officers (CSOs), such as who made the mistake, when, and what service it was for. this is so we can gather data which would show areas where CSO's are repeatedly making mistakes so we can feed this back to them and train them in those areas if need be.
i currently have a report where an CSOs name is entered along with a date range and it produces the report showing the number of errors made for each service for that date range.
the code used is -
=Sum(IIf([Service]="Housing",1,0))
=Sum(IIf([Service]="Environmental Health",1,0))
etc etc for each Service.
The problem i have is that not every CSO does EVERY service and so there are usually a few results showing as "0". and i cannot be sure if thats because they dont do the service or if they are just very good at that service.
Being absolutely useless at SQL (or any other possible way of fixing this) i cannot figure out how to HIDE the entries that produce the zero value.
any help here would be greatly appreciated!
Assuming you have a table with the fields CSO, Service, FeedbackComments you could modify the report record source to
SELECT [CSO], [Service], Count([FeedbackComments])
FROM [FeedbackTable]
GROUP BY [CSO], [Service];
Then services which have no records will not appear on the report.
I don't understand exactly what you want. But I want to mention you can use the COUNT() function along with SUM(). A count >0 will reveal if 0 means '0' instances or '0' errors.