SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[sp_GetOsztalyokHaviHianyzasiOsszesitoje]
  @tanevID int,
  @intezmenyId int

AS 
BEGIN

declare @honapok table(honap int, honapnev nvarchar(max));
insert into @honapok
select distinct d.c_value, d.c_name as Honap from t_dictionaryitembase d where c_type like 'honap%' order by d.c_value

select honapnev from @honapok

DECLARE kur CURSOR FOR 
select distinct d.c_value as Honap from t_dictionaryitembase d where c_type like 'honap%'

DECLARE @Honap int

OPEN kur
FETCH NEXT FROM kur INTO @Honap

WHILE @@FETCH_STATUS = 0 BEGIN
  create table #tabla(COLUMN379 nvarchar(max), [1] int,[2] int,[3] int,[4] int,[5] int,[6] int,[7] int,[8] int,[9] int,[10] int,[11] int,[12] int,[13] int,[14] int,[15] int,[16] int,[17] int,[18] int,[19] int,[20] int,[21] int,[22] int,[23] int,[24] int,[25] int,[26]  int,[27] int,[28] int,[29] int,[30] int,[31] int, COLUMN2672 int, COLUMN1910 int, COLUMN5197 int, COLUMN1786 int, COLUMN1787 int, COLUMN1788 int, COLUMN1789 int, COLUMN1911 int)
  insert into #tabla
  EXEC [dbo].[sp_GetOsztalyHaviMulasztasaiOsszesitoje_honapra] @tanevID, @intezmenyId, @honap
  SELECT * from #tabla
  drop table #tabla
      FETCH NEXT FROM kur INTO @honap
END

CLOSE kur
DEALLOCATE kur


END
