SQLTeam.com | Weblogs | Forums

Terminate stored procedure when a field is blank


#1

Hi,

I have a .net page with fields for users to supply values
and a submit button that calls a stored procedure. If field @NumUnits is blank, I want the SP to
terminate. Can someone please help?

Thanks


#2

Here's the SP. Thanks

USE [MyDatabase]
GO
/****** Object: StoredProcedure [dbo].[InsertInventory] Script Date: 06/12/2015 09:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author: Anucha Wells
-- Create date: 3/20/15
-- Description: Insert Daily Inventory
-- =============================================
ALTER PROCEDURE [dbo].[InsertInventory]
-- Add the parameters for the stored procedure here
@InventoryDate AS Datetime,
@ProductType AS nvarchar(15),
@Thickness AS nvarchar(10),
@ProductName AS nvarchar(15),
@Grade AS nvarchar(15),
@NumUnits AS nvarchar(10),
@UOM AS nvarchar(15)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO [dbo].[tblDailyInventory]
([InventoryDate],
[ProductType],
[Thickness],
[ProductName],
[Grade],
[NumUnits],
[UOM])
VALUES
(@InventoryDate,
@ProductType,
@Thickness,
@ProductName,
@Grade,
@NumUnits,
@UOM)
END


#3
ALTER PROCEDURE ...
...
AS
SET NOCOUNT ON;
IF @NumUnits IS NULL OR @NumUnits = ''
    RETURN;
--rest of proc here

#4

That worked. Thank you very much.