Need to add a Column to signify Active or Termed Status - tsql

I am creating a table that has a variety of Employee data in fields. I need to add a column that will display an "Active" or "Termed" status based weather there is a date in the Termination Date column.
For example, If the employee has a date in the StartDate column but not in the EndDate column then the EmpStatus Column will return an "Active" status. If there is a date in the EndDate column then it will return a "Termed" Status.
I am loading a master table from a view is the fastest and easiest way to do it.
The question is, where can I find a script that will perform the function I need.

SELECT CASE WHEN EndDate is not null then 'Termed'
WHEN StartDate is not null then 'Active'
else 'unknown' end as EmpStatus
FROM employee

Related

Validation on range of dates

I have a lookup table as follows:
StartDate
EndDate
Name
01/01/2022
31/01/2022
Custom Name 1
01/02/2022
28/02/2022
Custom Name 2
etc.
On another sheet I have a date column and a name column. I want to autopopulate the name from this lookup table based on the date being between one of the start and end dates.
What validation formula do I need to apply to get this to work?

How do you filter a date table based on two separate date filters in PowerBI?

I have 3 tables StartDateSelect EndDateSelect and Date.
Date is what is driving my other table in the report.
Note Date3 is formatted as 123ABC to show "Latest" for the latest date after refresh else show Date. This is to make sure that for each scheduled refresh, I will always have the filters show as the latest date so the user doesn't have to switch it each day.
In my dashboard, I have two filters for date selection (start and End). I have selected the dates I want as shown:
I want the Dates table to be filtered for values BETWEEN the selected Start Date and Selected End Date (which in most cases will be stuck on "Latest")
I've played with filters on visuals and index columns with no luck, and I can't seem to get this to work. Or if there's another way to do this. The Between filter won't work with a word called "Latest" in it as it's ABC123 format by default.
Create a measure as follows.
Measure =
VAR cursor = MAX('Date'[Dates])
VAR startDate = MAX(StartDatesSelect[Dates])
VAR endDate = MAX(EndDateSelect[Dates])
RETURN IF(cursor IN DATESBETWEEN('Date'[Dates], startDate, endDate),1,0)
Set a filter on your visual as follows:
That's it.

how to query attendee with filter duplicate record

i want to query attendee table based on date range. The existing system enables user to checkin or checkout multiple times each day. Now the problem is, how to get the data which is filtered, where for each day i get first checkin timestamp, and last checkout timestamp per user ID.
Here are the screenshots :
current data
expected result :
extected data (get latest checkout each day per user ID)
FYI, i am using postgresql 9.6 with PgAdmin4
demo:db<>fiddle
SELECT
createdby,
check_date::date,
MIN(check_date) as check_in, -- 2
MAX(check_date) as check_out
FROM mytable
GROUP BY createdby, check_date::date -- 1
Group by your user (I guess, its createdby in your case) and the date (converted from the timestamp value)
Aggregate with MIN and MAX functions.
In case the the last attendee value could be CHECK_IN and the first one could be CHECK_OUT, you can add the FILTER clause as demonstrated below, to filter the MIN/MAX inputs only for the relevant attendee records:
SELECT
createdby,
check_date::date,
MIN(check_date) FILTER (WHERE attendee = 'CHECK_IN') as check_in,
MAX(check_date) FILTER (WHERE attendee = 'CHECK_OUT') as check_out
FROM mytable
GROUP BY createdby, check_date::date

Repository Query Language select data between data range

I'm beginner of RQl and I have a product table which have end date for all the products. Now I want to retrieve all products who's end date is null within given time period.
I tried below.
endDate IS NULL BETWEEN ?1 AND ?2;
But it's not work. Can anyone help me.

SQLite in iPhone:I want to Retrieving 1 row for each date from sqlite

i only want to know that whether data is available for any specific date or not.If there are more than one data with the same date, i do not want to fetch all the data.I try to use
LIMIT 0,1 in where clause but it means it will fetch total 1 data for the given date range.
So please tell me the way to fetch data between a date range with 1 data for particular date.
Thanks.
Very simple example:
CREATE TABLE(
name,
date
);
insert into events values ("foo", "2008-01-01");
insert into events values ("bar", "2008-01-01");
insert into events values ("goo", "2009-01-01");
insert into events values ("gai", "2009-01-01");
select max(name), date from events group by date;
Output:
foo|2008-01-01
goo|2009-01-01
See How to select the first/least/max row per group in SQL