I have been working on a project for a very long time and I can't seem to find out how to do it. I have a looping code and a function combined but can't seem to get the output I wanted to see.
My code is like this:
WITH CTE AS(SELECT 1 as DayUNION ALLSELECT Day+1 FROM CTEWHERE Day < 15), Name as (Select * from fn_logs(@Month, @Year,@date_from,@date_to))SELECT CTE.Day, CASE WHEN Name.DAtee != CTE.Day THEN Name.Fullname ELSE Name.Fullname END as Fullname,CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.AMIN END as AMIN, CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.AMOUT END as AMOUT, CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.PMIN END as PMIN, CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.PMOUT END as PMOUTFROM CTE, Namegroup by CTE.Day,Name.Fullname,Name.AMIN,Name.AMOUT,Name.PMIN,Name.PMOUT
where the **Name.DAtee** gets the day of the date
The output I wanted to happen was like:
Day Fullname AM-IN AM-OUT PM-IN PM-OUT1 Ara Ast 8:00 12:00 12:03 5:002 Ara Ast 7:51 12:22 12:23 5:103 Ara Ast 1 Clara Est 8:01 12:12 12:25 5:072 Clara Est 3 Clara Est 7:41 12:02 12:15 5:00
I wanted to show all the days a single employees has logged and when no date was logged, it will automatically show no value. The output I get was like:
Day Fullname AM-IN AM-OUT PM-IN PM-OUT1 Ara Ast 8:00 12:00 12:03 5:002 Ara Ast 3 Ara Ast 1 Ara Ast 2 Ara Ast 7:51 12:22 12:23 5:103 Ara Ast 1 Ara Ast 2 Ara Ast 3 Ara Ast
The values seem to repeat and whenever the value was not equal to the date, it prints the no value. Sorry I am kinda still in the learning stage of the sql server coding.
Thanks in advance.