265 lines
14 KiB
Transact-SQL
265 lines
14 KiB
Transact-SQL
GO
|
|
/****** Object: StoredProcedure [dbo].[sp_GetTanulokFeleviTantargyiStatisztika] Script Date: 2016.04.12. 9:32:41 ******/
|
|
SET ANSI_NULLS ON
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON
|
|
GO
|
|
-- =============================================
|
|
-- Author: Kelemen Attila
|
|
-- Create date: 2016. 04. 11.
|
|
-- Description: Tárolt eljárás a tanulók félévi tantárgyi statisztikái nevű nyomtatványhoz
|
|
-- =============================================
|
|
IF OBJECT_ID('sp_GetTanulokFeleviTantargyiStatisztika') IS NOT NULL BEGIN
|
|
DROP PROCEDURE [sp_GetTanulokFeleviTantargyiStatisztika]
|
|
END
|
|
GO
|
|
|
|
CREATE PROCEDURE [sp_GetTanulokFeleviTantargyiStatisztika]
|
|
@TanevId int,
|
|
@IntezmenyId int
|
|
AS
|
|
BEGIN
|
|
-- SET NOCOUNT ON added to prevent extra result sets from
|
|
-- interfering with SELECT statements.
|
|
declare @kezdodatum as date=(select distinct tr.c_datum from t_tanevrendje tr where c_naptipusa=1394);
|
|
declare @vegdatum as date=(select distinct tr.c_datum from t_tanevrendje tr where c_naptipusa=1400);
|
|
|
|
--Tanulók
|
|
create table #tanulok (Id int, Nev nvarchar(max), Osztaly int, Rendez nvarchar(max))
|
|
insert into #tanulok
|
|
select t.id as Tanulo, f.c_nyomtatasinev as Nev, tcs.c_osztalycsoportid as Osztaly, ocs.c_nev as Rendez from t_tanulo t
|
|
inner join t_tanulocsoport tcs on t.id=tcs.c_tanuloid and tcs.c_intezmenyid=@intezmenyid and tcs.c_tanevid=@tanevid and tcs.torolt='F'
|
|
inner join t_osztaly o on o.id=tcs.c_osztalycsoportid and o.c_alintezmenyid=@intezmenyid and o.c_altanevid=@tanevid and o.torolt='F'
|
|
inner join t_osztalycsoport ocs on ocs.id=o.id and ocs.c_intezmenyid=@intezmenyid and ocs.c_tanevid=@tanevid and ocs.torolt='F'
|
|
inner join t_felhasznalo f on f.id=t.id and f.torolt='F'
|
|
where t.c_alintezmenyid=@IntezmenyId and t.c_altanevid=@tanevid
|
|
order by Osztaly, Tanulo
|
|
insert into #tanulok values (-1, 'Összesen: ', -1, 'zzzz')
|
|
|
|
--Értékelések
|
|
create table #ertekeles(Tanulo int, Tantargy int, Ertekeles nvarchar(max))
|
|
insert into #ertekeles
|
|
select distinct te.c_tanuloid as Tanulo, te.c_tantargyid as Tantargy,
|
|
stuff((select ', '+isnull(cast(d.c_value as varchar(max)),'') from t_tanuloertekeles teOsszefuz
|
|
inner join (select distinct d.id, d.c_value from t_dictionaryitembase d) d on d.id=teOsszefuz.c_osztalyzat
|
|
where teOsszefuz.c_tanuloid=te.c_tanuloid and teOsszefuz.c_tantargyid=te.c_tantargyid and teOsszefuz.c_ertekelestipusa=1518
|
|
and teOsszefuz.torolt='F' and teOsszefuz.c_tanevid=@tanevid and teOsszefuz.c_intezmenyid=@intezmenyid
|
|
and convert(date,teOsszefuz.c_ertekelesdatum)>@kezdodatum and convert(date,teOsszefuz.c_ertekelesdatum)<@vegdatum
|
|
for xml path('')),1,1,'') as Ertekeles
|
|
from t_tanuloertekeles te
|
|
where te.c_tantargyid is not null and te.c_tanuloid in (select id from #tanulok)
|
|
|
|
insert into #ertekeles
|
|
select -1, Tantargy, Atlag from
|
|
(select te.c_tantargyid as Tantargy, round(avg(convert(float,d.c_value)),2) as Atlag from t_tanuloertekeles te
|
|
inner join (select distinct d.id, d.c_value from t_dictionaryitembase d) d on d.id=te.c_osztalyzat
|
|
where te.c_ertekelestipusa=1518 and te.torolt='F' and te.c_osztalyzat is not null and te.c_tantargyid is not null
|
|
and te.c_tanevid=@tanevid and te.c_intezmenyid=@intezmenyid
|
|
and convert(date,te.c_ertekelesdatum)>@kezdodatum and convert(date,te.c_ertekelesdatum)<@vegdatum
|
|
group by te.c_tantargyid)a
|
|
|
|
--Osztályátlag
|
|
create table #tanuloavg(Tanulo int, Atlag float)
|
|
insert into #tanuloavg
|
|
select te.c_tanuloid as Tanulo, round(avg(convert(float,d.c_value)),2) as Atlag from t_tanuloertekeles te
|
|
inner join (select distinct d.id, d.c_value from t_dictionaryitembase d) d on d.id=te.c_osztalyzat
|
|
where te.c_ertekelestipusa=1518 and te.torolt='F' and te.c_osztalyzat is not null and te.c_tantargyid is not null
|
|
and te.c_tanevid=@tanevid and te.c_intezmenyid=@intezmenyid
|
|
and convert(date,te.c_ertekelesdatum)>@kezdodatum and convert(date,te.c_ertekelesdatum)<@vegdatum
|
|
group by te.c_tanuloid
|
|
|
|
--Szorgalom, magatartás
|
|
declare @szorgmag table (Tanulo int, Szorgalom nvarchar(max), Magatartas nvarchar(max))
|
|
insert into @szorgmag
|
|
select distinct te.c_tanuloid as Tanulo,
|
|
--szorgalom
|
|
stuff((select ', '+isnull(cast(d.c_value as varchar(max)),'') from t_osztalyfonokiertekeles oe
|
|
inner join (select distinct d.id, d.c_value from t_dictionaryitembase d) d on d.id=oe.c_szorgalom
|
|
inner join t_tanuloertekeles teSz on teSz.id=oe.id
|
|
where teSz.c_tanuloid=te.c_tanuloid and oe.torolt='F' and convert(date,teSz.c_ertekelesdatum)>@kezdodatum and convert(date,teSz.c_ertekelesdatum)<@vegdatum
|
|
for xml path('')),1,1,'') as Szorgalom,
|
|
--magatartás
|
|
stuff((select ', '+isnull(cast(d.c_value as varchar(max)),'') from t_osztalyfonokiertekeles oe
|
|
inner join (select distinct d.id, d.c_value from t_dictionaryitembase d) d on d.id=oe.c_magatartas
|
|
inner join t_tanuloertekeles teM on teM.id=oe.id
|
|
where teM.c_tanuloid=te.c_tanuloid and oe.torolt='F'
|
|
and convert(date,teM.c_ertekelesdatum)>@kezdodatum and convert(date,teM.c_ertekelesdatum)<@vegdatum
|
|
for xml path('')),1,1,'') as Magatartas
|
|
from t_tanuloertekeles te
|
|
where te.c_tanuloid in (select id from #tanulok)
|
|
|
|
--Mulasztások
|
|
declare @mulasztas table (Tanulo int, Osztaly int, MulasztasTipus int, IgazoltE nvarchar(1), GaykorlatiE nvarchar(1), Keses int)
|
|
insert into @mulasztas
|
|
select tm.c_oratanuloiid Tanulo, tao.c_osztalycsoportid as Osztaly, tm.c_tipus MulasztasTipus, tm.c_igazolt as IgazoltE, t.c_gyakorlati as GyakorlatiE, tm.c_kesespercben Keses from t_tanulomulasztas tm
|
|
inner join t_tanulocsoport tcs on tcs.c_tanuloid=tm.c_oratanuloiid and tcs.torolt='F' and tcs.c_tanevid=@tanevid and tcs.c_intezmenyid=@intezmenyid
|
|
inner join t_tanitasiora tao on tao.id=tm.c_tanitasiorakid and tao.torolt='F' and tao.torolt='F' and tao.c_tanevid=@tanevid and tao.c_intezmenyid=@intezmenyid
|
|
inner join t_tantargy t on t.id=tao.c_tantargyid and t.torolt='F'
|
|
where tm.torolt='F' and tm.c_intezmenyid=@intezmenyid and tm.c_tanevid=@tanevid
|
|
and convert(date,tao.c_datum)>@kezdodatum and convert(date,tao.c_datum)<@vegdatum
|
|
|
|
create table #temp (Tanulo int, Szorgalom nvarchar(max),Magatartas nvarchar(max),oih int, onih int, oik int, onik int)
|
|
insert into #temp
|
|
select distinct t.id, sz.szorgalom, sz.magatartas, oih.oih, onih.onih, oik.oik, onik.onik from #tanulok t
|
|
left join @szorgmag sz on sz.tanulo=t.id
|
|
--igazolt hiányzások
|
|
left join (select m.Tanulo Tanulo, count(m.MulasztasTipus) oih from @mulasztas m where m.IgazoltE='T' and m.MulasztasTipus=1500 group by Tanulo )oih on oih.Tanulo=t.id
|
|
|
|
--igazolatlan hiányzások
|
|
left join (select m.Tanulo Tanulo, count(m.MulasztasTipus) onih from @mulasztas m where m.IgazoltE='F' and m.MulasztasTipus=1500 group by Tanulo )onih on onih.Tanulo=t.id
|
|
|
|
--igazolt késések
|
|
left join (select m.Tanulo Tanulo, sum(m.keses) oik from @mulasztas m where m.IgazoltE='T' and m.MulasztasTipus=1499 group by Tanulo)oik on oik.Tanulo=t.id
|
|
|
|
--igazolatlan késések
|
|
left join (select m.Tanulo Tanulo, sum(m.keses) onik from @mulasztas m where m.IgazoltE='F' and m.MulasztasTipus=1499 group by Tanulo)onik on onik.Tanulo=t.id
|
|
|
|
declare @cols as nvarchar(max),
|
|
@colsIn as nvarchar(max),
|
|
@query as nvarchar(4000);
|
|
|
|
select @cols= isnull(@cols + ',','') +quotename(Tantargy) + ' as '+quotename(nev),
|
|
@colsIn= isnull(@colsIn + ',','') +quotename(Tantargy)
|
|
from (select distinct t.id as Tantargy, t.c_nev as nev from t_foglalkozas f
|
|
inner join t_tantargy t on f.c_tantargyid=t.id) Tantargy
|
|
|
|
set @query='
|
|
select t.Nev as ''COLUMN108'', ocs.c_nev as ''COLUMN5286'', temp.Szorgalom as ''COLUMN2620'', temp.Magatartas as ''COLUMN2619'', '+@cols+', tavg.Atlag as ''COLUMN1817'', temp.oih as ''COLUMN5247'', temp.onih as ''COLUMN5254'', temp.oik as ''COLUMN5255'', temp.onik as ''COLUMN5256''
|
|
from #tanulok t
|
|
left join (select * from #ertekeles pivot (max(Ertekeles) for Tantargy in ('+@colsIn+'))pv) ertekeles on ertekeles.Tanulo=t.Id
|
|
left join #temp temp on temp.Tanulo=t.id
|
|
left join t_felhasznalo f on f.id=t.Id
|
|
left join t_osztalycsoport ocs on ocs.id=t.Osztaly
|
|
left join #tanuloavg tavg on tavg.tanulo=t.id
|
|
order by t.Rendez
|
|
'
|
|
EXEC sp_executesql @query
|
|
|
|
/*drop table #mulasztastmp */
|
|
drop table #tanulok
|
|
drop table #ertekeles
|
|
drop table #tanuloavg
|
|
|
|
End
|
|
|
|
|
|
GO
|
|
|
|
-- -- SET NOCOUNT ON added to prevent extra result sets from
|
|
-- -- interfering with SELECT statements.
|
|
-- SET NOCOUNT ON;
|
|
-- DECLARE @cols NVARCHAR(max)
|
|
|
|
-- SELECT
|
|
-- T_FELHASZNALO_OSSZES.ID TanuloID,
|
|
-- C_NYOMTATASINEV Tanulo,
|
|
-- OsztalyCsoport.C_NEV Osztaly,
|
|
-- Tantargy.C_NEV Tantargy,
|
|
-- DIB.C_VALUE Osztalyzat
|
|
-- INTO #Jegyek
|
|
-- FROM T_FELHASZNALO_OSSZES
|
|
-- INNER JOIN T_TANULOERTEKELES_OSSZES TanuloErtekeles ON T_FELHASZNALO_OSSZES.ID = TanuloErtekeles.C_TANULOID AND TanuloErtekeles.C_ERTEKELESTIPUSA = 1519 --Félévi jegy/értékelés
|
|
-- AND TanuloErtekeles.TOROLT='F' AND TanuloErtekeles.C_OSZTALYZAT IS NOT NULL
|
|
-- INNER JOIN T_OSZTALYZATERTEKELES_OSSZES OsztalyzatErtekeles ON TanuloErtekeles.ID = OsztalyzatErtekeles.ID AND OsztalyzatErtekeles.TOROLT='F'
|
|
-- INNER JOIN T_TANTARGY_OSSZES Tantargy ON TanuloErtekeles.C_TANTARGYID = Tantargy.ID AND Tantargy.TOROLT = 'F'
|
|
-- INNER JOIN T_TANULOCSOPORT_OSSZES TanuloCsoport ON T_FELHASZNALO_OSSZES.ID = TanuloCsoport.C_TANULOID AND TanuloCsoport.TOROLT='F'
|
|
-- INNER JOIN T_OSZTALYCSOPORT_OSSZES OsztalyCsoport ON TanuloCsoport.C_OSZTALYCSOPORTID = OsztalyCsoport.ID AND TanuloCsoport.TOROLT='F'
|
|
-- INNER JOIN T_OSZTALY_OSSZES Osztaly ON OsztalyCsoport.ID = Osztaly.ID AND Osztaly.TOROLT='F'
|
|
-- INNER JOIN T_DICTIONARYITEMBASE_OSSZES DIB ON TanuloErtekeles.C_OSZTALYZAT = DIB.ID
|
|
-- WHERE T_FELHASZNALO_OSSZES.TOROLT='F'
|
|
-- and T_FELHASZNALO_OSSZES.C_TANEVID = @TanevId
|
|
|
|
|
|
|
|
--SELECT @cols = STUFF(( SELECT DISTINCT TOP 100 PERCENT
|
|
-- '],[' + #Jegyek.Tantargy
|
|
-- FROM #Jegyek
|
|
-- ORDER BY '],[' + #Jegyek.Tantargy
|
|
-- FOR XML PATH('')
|
|
-- ), 1, 2, '') + ']'
|
|
----SET @cols = '[tanID],[TanuloNev],' +@cols;
|
|
|
|
--DECLARE @query NVARCHAR(max)
|
|
--SET @query = 'SELECT TanuloID, Tanulo,Osztaly,' + @cols+
|
|
--' INTO #TanuloTantargyOsztalyzatok FROM
|
|
--(SELECT * FROM #Jegyek ) p
|
|
--PIVOT
|
|
--(
|
|
--MAX([Osztalyzat])
|
|
--FOR Tantargy IN
|
|
--( '+
|
|
--@cols +' )
|
|
--) AS pvt
|
|
--ORDER BY Osztaly,Tanulo;
|
|
--'
|
|
|
|
--IF(@cols IS NULL)
|
|
--BEGIN
|
|
-- SET @query = 'SELECT TanuloID, Tanulo,Osztaly,Tantargy INTO #TanuloTantargyOsztalyzatok FROM (SELECT * FROM #Jegyek) AS jegyek
|
|
-- ';
|
|
--END
|
|
|
|
--SET @query +=
|
|
--'SELECT #TanuloTantargyOsztalyzatok.*, Atlag.Atlag, Bukasok.BukasokSzama,
|
|
--Mulasztasok.IgazoltOrak, Mulasztasok.IgazolatlanOrak, Mulasztasok.IgazoltKesesPercek,Mulasztasok.IgazoltKesesOrak, Mulasztasok.IgazolatlanKesesPercek, Mulasztasok.IgazolatlanKesesOrak
|
|
|
|
|
|
-- from #TanuloTantargyOsztalyzatok
|
|
--INNER JOIN
|
|
-- (SELECT TanuloErtekeles.TanuloID,
|
|
-- CAST(AVG(CAST(DIB.C_VALUE as float)) as decimal(10,2)) Atlag
|
|
|
|
-- FROM (SELECT ID, C_TANTARGYID TantargyID, C_TANULOID TanuloID, C_ERTEKELESTIPUSA ErtekelesTipus, C_OSZTALYZAT Osztalyzat
|
|
-- FROM T_TANULOERTEKELES WHERE TOROLT=''F'' AND T_TANULOERTEKELES.C_ERTEKELESTIPUSA = 1519 AND C_OSZTALYZAT IS NOT NULL) TanuloErtekeles
|
|
-- INNER JOIN (SELECT ID,C_VALUE FROM T_DICTIONARYITEMBASE) DIB ON TanuloErtekeles.Osztalyzat = DIB.ID
|
|
|
|
-- GROUP BY TanuloID) Atlag ON #TanuloTantargyOsztalyzatok.TanuloID = Atlag.TanuloID
|
|
|
|
|
|
--LEFT JOIN (SELECT T_TANULOERTEKELES.C_TANULOID, COUNT(1) BukasokSzama FROM T_TANULOERTEKELES
|
|
-- WHERE T_TANULOERTEKELES.TOROLT=''F'' AND T_TANULOERTEKELES.C_ERTEKELESTIPUSA = 1519 AND T_TANULOERTEKELES.C_OSZTALYZAT = 1501
|
|
-- GROUP BY C_TANULOID) Bukasok
|
|
|
|
-- ON #TanuloTantargyOsztalyzatok.TanuloID = Bukasok.C_TANULOID
|
|
|
|
-- LEFT JOIN (select Tanulo.ID TanuloID, IgazoltOra.Ertek IgazoltOrak, IgazolatlanOra.Ertek IgazolatlanOrak, IgazoltKesesPercek.Ertek IgazoltKesesPercek,
|
|
--IgazoltKesesOrak.Ertek IgazoltKesesOrak, IgazolatlanKesesPercek.Ertek IgazolatlanKesesPercek, IgazolatlanKesesOrak.Ertek IgazolatlanKesesOrak
|
|
-- from (
|
|
|
|
|
|
-- (SELECT ID FROM T_FELHASZNALO) Tanulo LEFT JOIN
|
|
|
|
--(select C_TANULOID TanuloID, C_OSSZESELSOFELEVMULASZTAS Ertek from T_TANULOMULASZTASSTATISZTIKA WHERE TOROLT=''F'' and C_STATISZTIKATIPUS = 1656)--igazolt óra
|
|
|
|
--IgazoltOra ON Tanulo.ID = IgazoltOra.TanuloID
|
|
|
|
--left join (select C_TANULOID TanuloID, C_OSSZESELSOFELEVMULASZTAS Ertek from T_TANULOMULASZTASSTATISZTIKA WHERE TOROLT=''F'' and C_STATISZTIKATIPUS = 1662)--igazolatlan óra
|
|
--IgazolatlanOra ON Tanulo.ID = IgazolatlanOra.TanuloID
|
|
|
|
--left join (select C_TANULOID TanuloID, C_OSSZESELSOFELEVKESESPERC Ertek from T_TANULOMULASZTASSTATISZTIKA WHERE TOROLT=''F'' and C_STATISZTIKATIPUS = 1664)--igazolt késés percek
|
|
--IgazoltKesesPercek ON Tanulo.ID=IgazoltKesesPercek.TanuloID
|
|
|
|
--left join (select C_TANULOID TanuloID, C_OSSZESELSOFELEVMULASZTAS Ertek from T_TANULOMULASZTASSTATISZTIKA WHERE TOROLT=''F'' and C_STATISZTIKATIPUS = 1664)--igazolt késés percek
|
|
--IgazoltKesesOrak ON Tanulo.ID=IgazoltKesesOrak.TanuloID
|
|
|
|
--left join (select C_TANULOID TanuloID, C_OSSZESELSOFELEVKESESPERC Ertek from T_TANULOMULASZTASSTATISZTIKA WHERE TOROLT=''F'' and C_STATISZTIKATIPUS = 1665)--igazolatlan késés percek
|
|
--IgazolatlanKesesPercek ON Tanulo.ID=IgazolatlanKesesPercek.TanuloID
|
|
|
|
--left join (select C_TANULOID TanuloID, C_OSSZESELSOFELEVMULASZTAS Ertek from T_TANULOMULASZTASSTATISZTIKA WHERE TOROLT=''F'' and C_STATISZTIKATIPUS = 1665)--igazolatlan késés percek
|
|
--IgazolatlanKesesOrak ON Tanulo.ID=IgazolatlanKesesOrak.TanuloID)
|
|
--) Mulasztasok ON #TanuloTantargyOsztalyzatok.TanuloID = Mulasztasok.TanuloID
|
|
--ORDER BY Osztaly,Tanulo
|
|
--'
|
|
|
|
--EXEC sp_executesql @query
|
|
|
|
|
|
--DROP TABLE #Jegyek
|
|
|
|
--END
|
|
|
|
|
|
|
|
--GO
|
|
|
|
|