kreta/Kreta.DataAccess.Migrations/DBScripts/Database/dbo/Stored procedures/sp_GetHozzatartozok.sql
2024-03-13 00:33:46 +01:00

42 lines
No EOL
2.2 KiB
Transact-SQL

-- =============================================
-- Description: Tanulók gondviselõinek belépési adatai
-- =============================================
DROP PROCEDURE IF EXISTS [dbo].[sp_GetHozzatartozok]
GO
CREATE PROCEDURE [dbo].[sp_GetHozzatartozok]
@osztalyId int = null,
@intezmenyId int,
@tanevId int
AS
BEGIN
SET NOCOUNT ON;
declare @Hozzaferesek table (Osztaly nvarchar(max), OsztalyId int, Intezmeny nvarchar(max), TanuloNev nvarchar(max), Gondviselo nvarchar(max), Azonosito nvarchar(max), Jelszo nvarchar(max), Link nvarchar(max))
insert into @Hozzaferesek
select distinct Osztaly.Osztaly, Osztaly.Osztalyid, ia.c_nev Intezmeny, f.c_nyomtatasinev TanuloNev, g.c_nev Gondviselo, fb.c_bejelentkezesinev Azonosito, fb.c_jelszo Jelszo, 'https://'+lower(i.c_azonosito)+'.e-kreta.hu' as Link from t_gondviselo g
inner join t_tanulo t on t.id=g.c_tanuloid and t.c_alintezmenyid=@intezmenyid and t.c_altanevid=@tanevid
inner join t_felhasznalo f on f.id=t.id and f.torolt='F'
inner join t_felhasznalobelepes fb on fb.c_gondviseloid=g.id and fb.torolt='F' and fb.C_KOTELEZOVALTOZTATNI = 'T'
left join (select tcs.c_tanuloid TanuloId, ocs.c_nev as Osztaly, o.Id OsztalyId from t_tanulocsoport tcs
inner join t_osztaly o on o.id=tcs.c_osztalycsoportid and o.torolt='F' and o.c_alintezmenyid=@intezmenyid and o.c_altanevid=@tanevid
inner join t_osztalycsoport ocs on ocs.id=o.id and ocs.c_intezmenyid=@intezmenyid and ocs.c_tanevid=@tanevid
AND ocs.C_FELADATKATEGORIAID = 7553 /*OktNevelesiKategoriaEnum.Alapkepzes*/
where tcs.torolt='F' and tcs.c_intezmenyid=@intezmenyid and tcs.c_tanevid=@tanevId) Osztaly on Osztaly.Tanuloid=t.id
inner join t_intezmenyadatok ia on ia.c_intezmenyid=t.c_alintezmenyid and ia.c_tanevid=@tanevId and ia.torolt='F'
inner join t_intezmeny i on i.id=ia.c_intezmenyid and i.torolt='F'
where g.torolt='F'
order by TanuloNev
if @osztalyId is null
begin
select Osztaly, Intezmeny, TanuloNev, Gondviselo, Azonosito, Jelszo, Link from @Hozzaferesek
end
else
begin
select Osztaly, Intezmeny, TanuloNev, Gondviselo, Azonosito, Jelszo, Link from @Hozzaferesek where Osztalyid=@osztalyid
end
End
go