I have to develop a report. I have:
The main report based on:
USE [db]
GO
/****** Object: StoredProcedure [dbo].[SCRIPT_1] Script Date: 14/07/2016 11:53:22 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[SCRIPT_1]
AS
set nocount on;
SELECT
Headers.Date AS InvDate,
Headers.PostedDate,
Headers.OurReference OurRefTr,
Headers.Userid UserTr,
Headers.Number
FROM
Headers WITH (READUNCOMMITTED)
where
Headers.Ledger='Purchases'
and Headers.OurReference Not Like '%CT'
And a subreport:
USE [DB]
GO
/****** Object: StoredProcedure [dbo].[SCRIPT_2] Script Date: 14/07/2016 12:00:53 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[SCRIPT_2]
@LogKey char(13)
AS
set nocount on;
SELECT
min([Log].[Date]) as MinLogDate
FROM
[Log] WITH (READUNCOMMITTED) WHERE @LogKey=[Log].[Key]
And I link the Headers.Number with the [Log].[Key]
I don’t know to write complicated stored procedures. The report is extremely slow, I assume because the tables Headers and Log are updated permanently with all the information that users input. Table Log in special is very big and live. Is there another way to write the scripts? Or a stored procedure to speed the report? Or is a temporary table any use?
I use SAP Crystal Reports and Microsoft SQL Server Management Studio.
The main report based on:
USE [db]
GO
/****** Object: StoredProcedure [dbo].[SCRIPT_1] Script Date: 14/07/2016 11:53:22 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[SCRIPT_1]
AS
set nocount on;
SELECT
Headers.Date AS InvDate,
Headers.PostedDate,
Headers.OurReference OurRefTr,
Headers.Userid UserTr,
Headers.Number
FROM
Headers WITH (READUNCOMMITTED)
where
Headers.Ledger='Purchases'
and Headers.OurReference Not Like '%CT'
And a subreport:
USE [DB]
GO
/****** Object: StoredProcedure [dbo].[SCRIPT_2] Script Date: 14/07/2016 12:00:53 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[SCRIPT_2]
@LogKey char(13)
AS
set nocount on;
SELECT
min([Log].[Date]) as MinLogDate
FROM
[Log] WITH (READUNCOMMITTED) WHERE @LogKey=[Log].[Key]
And I link the Headers.Number with the [Log].[Key]
I don’t know to write complicated stored procedures. The report is extremely slow, I assume because the tables Headers and Log are updated permanently with all the information that users input. Table Log in special is very big and live. Is there another way to write the scripts? Or a stored procedure to speed the report? Or is a temporary table any use?
I use SAP Crystal Reports and Microsoft SQL Server Management Studio.