Avatar of mlcktmguy
mlcktmguy
Flag for United States of America

asked on 

Testing a Stored Procedure and showing results

I am trying to unit test a stored procedure by creating another sp 'spzBogus' that hard codes variables to execute the SP.

Once I completed the testSP 'spzBogus', I check it(Checkmark button), then click the '! Execute' button in the menu panel.

I would like to see the values of the return fields after the execute.  I don't see anything in the message panel other than  'Command(s) completed successfully.'

I have a Print statement to try and show one of the returned values but nothing showed in the Messages panel.

1. Am I executing the SP correctly (clicking the '! Execute' button
2. How can I show my return values (@FaceSum, @PenaltySum, @InterestSum, @LienSum, @SvcChgSum)  to know that the called porcedure is executing correctly.

Here is the SP to test another SP
 
USE [JTSConversion]
GO
/****** Object:  StoredProcedure [dbo].[spTAYearSummary]    Script Date: 12/7/2015 9:26:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
Alter PROCEDURE [dbo].[spzBogus] 
	-- Add the parameters for the stored procedure here
--	<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>, 
---	<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	declare @nextTAIDofResultSet	int,
			@passedFromYear			int,
			@passedThruYear			int,
			@FaceSum				real,
			@PenaltySum				real,
			@InterestSum			real,
			@LienSum				real,
			@SvcChgSum				real

	Set @nextTAIDofResultSet	= 543972
	Set @passedFromYear			= 0
	set	@passedThruYear			= 9999
	set	@FaceSum				= 0
	set	@PenaltySum				= 0
	set	@InterestSum			= 0
	set	@LienSum				= 0
	set	@SvcChgSum				= 0

	Execute spTAYearSummary @nextTAIDofResultSet, @passedFromYear, @passedThruYear, @FaceSum, @PenaltySum, @InterestSum, @LienSum, @SvcChgSum

	print 'facesum: ' + @FaceSum


    -- Insert statements for procedure here
	
END
GO

Open in new window


This is the SP I am trying to test:  Yes, I'm aware that the return values are hard coded.  Once i know I have the setup correct, I'll uncomment the 'Select' to make sure it works correctly.

USE [JTSConversion]
GO
/****** Object:  StoredProcedure [dbo].[spTAYearSummary]    Script Date: 12/7/2015 9:26:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		MJO
-- Create date: 12/7/15
-- Description:	Summarize TA Years
-- =============================================
ALTER PROCEDURE [dbo].[spTAYearSummary] 
	-- Add the parameters for the stored procedure here
	@passedTaxAuthorityID int = 0, 
	@passedFromYear       int = 0,
	@passedThruYear       Int = 9999,
	@returnFaceSum        Real OUTPUT,
	@returnPenaltySum     Real OUTPUT,
	@returnInterestSum    Real OUTPUT,
	@returnLienSum        Real OUTPUT,
	@returnSvcChgSum      Real OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
---	SELECT  
---	   @returnFaceSum = SUM([FaceBal]) , 
---	   @returnPenaltySum = SUM([PenaltyBal]), 
---	   @returnInterestSum = SUM([InterestBal]), 
---	   @returnLienSum = SUM([LienCostBal]), 
---	   @returnSvcChgSum = SUM([SvcChgBal])
---	FROM tblTaxYears 
---	WHERE TaxAuthorityRecID =  @passedTaxAuthorityID and 
---	   PayStatusID <> 1 and
---	   TaxYear Between @passedFromYear and @passedThruYear

	   set @returnFaceSum = 1.23
	   set @returnPenaltySum = 2.34
	   set @returnInterestSum = 3.45
	   set @returnLienSum = 4.56
	   set @returnSvcChgSum = 5.67

END

Open in new window

Microsoft SQL Server

Avatar of undefined
Last Comment
mlcktmguy

8/22/2022 - Mon