Guys i have another requirement on same but this time i do not want show count instead json data itself.
i tried doing it but facing duplicate record issue.
declare @tab table
(
jsonid int identity(1,1),
empid int,
jsonLinks nvarchar(max)
)
declare @temp table
(
id int identity(1,1),
empid int,
worklocation varchar(255),
AttendedDate date,
supervisor varchar(255),
Manager varchar(255),
Remarks varchar(255)
)
insert into @temp(empid,worklocation,AttendedDate,supervisor,Manager,Remarks)
values(1,'NewYork','2020-02-01','mike','ching chang',null)
insert into @temp(empid,worklocation,AttendedDate,supervisor,Manager,Remarks)
values(2,'NewYork','2020-02-02','tyson','Adam',null)
insert into @temp(empid,worklocation,AttendedDate,supervisor,Manager,Remarks)
values(1,'NewYork','2020-02-02','mike','ching chang',null)
insert into @tab(empid,jsonLinks)
values(1,'[{"file_name":"9EnzA3EoRo2rXnsBhusJJYuqenLI1G3m.png","file_type":"png"}]')
insert into @tab(empid,jsonLinks)
values(1,'[{"file_name":"QN2XCzonsG5uaXpubVDnJoxwmr9IVy6m.jpg","file_type":"jpg"},
{"file_name":"hTP04FHuWSFqKwKpaKcvyECnoUiiNLGb.png","file_type":"png"},
{"file_name":"QvxU1WMoG4pUykLBc83oSfT1RyT88yzk.png","file_type":"png"},
{"file_name":"n2cJ8E3BidA6FheEi7SNYZaU7VyWR7CA.jpg","file_type":"jpg"},
{"file_name":"sMyHyHJELDmvJGQEwns4bAjyhqusXk2g.jpg","file_type":"jpg"},
{"file_name":"wtMV3xnx1dFdl1XvHItPw8yGF9xNTnTQ.jpg","file_type":"jpg"},
{"file_name":"QqBpwaVLUEhj6iCZzC2rt8eFzT8SdMEI.jpg","file_type":"jpg"},
{"file_name":"Ng6RFKPep9Ium5D38KZ992Txa9gvMOdN.jpg","file_type":"jpg"}]')
insert into @tab(empid,jsonLinks)
values(2,'[{"file_name":"n79zmC7IW9NzhxLLDY6aIDasPgrZ7q3n.png","file_type":"png"},
{"file_name":"OwjRpCPhyu71hGekWrvTiqkuIWkjRLiR.png","file_type":"png"}]')
;with cte as
(
select -- distinct Row_number() over(partition by t.AttendedDate order by t.AttendedDate) as rowid,
t.AttendedDate,
t.empid ,
t.worklocation,
t.supervisor ,
t.Manager,
t.Remarks,
tb.jsonLinks
from @temp t inner join @temp t2 on t.AttendedDate = t2.AttendedDate
and t.empid = t2.empid
inner join @tab tb
on t.empid = tb.empid
--inner join @temp t2 on t.AttendedDate = t2.AttendedDate
where t.empid = 1
)
select distinct empid,AttendedDate,worklocation,supervisor,Manager,Remarks,jsonLinks
from cte
group by AttendedDate,empid,worklocation,supervisor,Manager,Remarks,jsonLinks