IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'V'   and [name] = 'hwv_PeriodenSaldiEx')
  DROP VIEW [dbo].[hwv_PeriodenSaldiEx]
GO
CREATE VIEW [dbo].[hwv_PeriodenSaldiEx]
AS
  SELECT 
    Typ,Konto,SaldoAlt,SaldoNeu, SaldoNeu - SaldoAlt AS SaldoBil
  FROM [hwv_PeriodenSaldi]
GO

/*------------------------------------------------------------*/
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Sel_Bilanz')
  DROP PROCEDURE [dbo].[up_Sel_Bilanz]
GO
CREATE PROCEDURE [dbo].[up_Sel_Bilanz]
  @RI integer
AS
   SELECT
       Z.[LstNr],Z.[LfdNr],Z.[PosNr],Z.[PosTyp],Z.[KtoTyp],Z.[KtoVon],Z.[KtoBis]
      ,Z.[Text],Z.[Tiefe],Z.[Still],Z.[Fett]

      ,convert(float,ISNULL((SELECT SUM(SaldoAlt) FROM [dbo].[hwv_PeriodenSaldiEx] S1
	WHERE S1.Typ = Z.KtoTyp AND S1.Konto >= Z.KtoVon AND S1.Konto <= Z.KtoBis
       ),0.00)) AS SaldoAlt

--     ,0 AS SaldoAlt

      ,convert(float,ISNULL((SELECT SUM(SaldoNeu) FROM [dbo].[hwv_PeriodenSaldiEx] S2
	  WHERE S2.Typ = Z.KtoTyp AND S2.Konto >= Z.KtoVon AND S2.Konto <= Z.KtoBis
         ),0.00)) AS SaldoNeu

--     ,0 AS SaldoNeu

      ,convert(float,ISNULL((SELECT SUM(SaldoBil) FROM [dbo].[hwv_PeriodenSaldiEx] S3
	WHERE S3.Typ = Z.KtoTyp AND S3.Konto >= Z.KtoVon AND S3.Konto <= Z.KtoBis
       ),0.00)) AS SaldoBil

    FROM [dbo].[ut_Bilanzzeilen] Z
    WHERE RecId = @RI
GO

/*
EXECUTE up_Sel_Bilanz 62
EXECUTE up_Sel_Bilanz 70
*/

IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_First_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_First_Bilanz_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Last_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_Last_Bilanz_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_Prior_Bilanz_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_Next_Bilanz_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Prior50_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_Prior50_Bilanz_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_Next50_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_Next50_Bilanz_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindL_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_FindL_Bilanz_Key00]
GO
IF 0 < (SELECT count(*) from [sysobjects] where [xtype] = 'P'   and [name] = 'up_FindF_Bilanz_Key00')
  DROP PROCEDURE [dbo].[up_FindF_Bilanz_Key00]
GO

CREATE PROCEDURE [dbo].[up_First_Bilanz_Key00]
AS
  EXECUTE [dbo].[up_First_Bilanzzeilen_Key00]
GO

CREATE PROCEDURE [dbo].[up_Last_Bilanz_Key00]
AS
  EXECUTE [dbo].[up_Last_Bilanzzeilen_Key00]
GO

CREATE PROCEDURE [dbo].[up_Next_Bilanz_Key00] @mRecNo integer
AS
  EXECUTE [dbo].[up_Next_Bilanzzeilen_Key00] @mRecNo
GO

CREATE PROCEDURE [dbo].[up_Prior_Bilanz_Key00] @mRecNo integer
AS
  EXECUTE [dbo].[up_Prior_Bilanzzeilen_Key00] @mRecNo
GO

CREATE PROCEDURE [dbo].[up_FindF_Bilanz_Key00] @xKey char(128),@xLen integer
AS
  EXECUTE [dbo].[up_FindF_Bilanzzeilen_Key00] @xKey, @xLen
GO

CREATE PROCEDURE [dbo].[up_FindL_Bilanz_Key00] @xKey char(128),@xLen integer
AS
  EXECUTE [dbo].[up_FindL_Bilanzzeilen_Key00] @xKey, @xLen
GO

