I wrote one stored procedure for testing an another stored procedure by passing different parameters and storing the count and time taken for executing the procedure in temp table.Procedure is better than function?
CREATE PROCEDURE [dbo].[SPTEST_NEW] AS
BEGIN
DECLARE @COUNT int;
DECLARE @STARTDATETIME DATETIME;
DECLARE @ENDDATETIME DATETIME;
DECLARE @TimeDiff NVARCHAR(50);
DECLARE @SPNAME VARCHAR(50);
DECLARE @Result TABLE
(
Cases NVARCHAR(100),
RecordCount INT,
ExecutionTime NVARCHAR(50)
)
DECLARE @Search TABLE
(
ID NVARCHAR(50),
NAME NVARCHAR(200),
FMT NVARCHAR(100)
)
SET @SPNAME ='dbo.[SEARCH_VALUE]';
SET @STARTDATETIME=GETDATE();
--Case#1: Search by All
INSERT INTO @Search
EXEC @SPNAME
@PRODUCTID =NULL,
@PRODUCTNAME =NULL,
@FORMAT =NULL
SET @ENDDATETIME=GETDATE();
SELECT @COUNT= @@ROWCOUNT
SET @TimeDiff = CONVERT(TIME,@ENDDATETIME-@STARTDATETIME);
INSERT INTO @Result values ('ALL', @COUNT,@TimeDiff)
-- Case#2 : Search by Product-ID
INSERT INTO @Search
EXEC @SPNAME
@PRODUCTID ='ABPROD-BLACK',
@PRODUCTNAME =NULL,
@FORMAT =NULL,
SET @ENDDATETIME=GETDATE();
SELECT @COUNT= @@ROWCOUNT
SET @TimeDiff = CONVERT(TIME,@ENDDATETIME-@STARTDATETIME);
INSERT INTO @Result values ('PROD-ID:ABPROD-BLACK', @COUNT,@TimeDiff)
--Case#3 : Search by FORMAT
INSERT INTO @Search
EXEC @SPNAME
@PRODUCTID =NULL,
@PRODUCTNAME =NULL,
@FORMAT ='SCHT',
SET @ENDDATETIME=GETDATE();
SELECT @COUNT= @@ROWCOUNT
SET @TimeDiff = CONVERT(TIME,@ENDDATETIME-@STARTDATETIME);
INSERT INTO @Result values ('Format:SCHT', @COUNT,@TimeDiff)
SELECT * FROM @Result
END
is above method is correct? or any other method.please suggest the method.
Aucun commentaire:
Enregistrer un commentaire