sql >> Base de Datos >  >> RDS >> Sqlserver

¿Cómo restringir NULL como parámetro al procedimiento almacenado SQL Server?

Puede verificar su NULL-ness en el sproc y RAISERROR para informar el estado a la ubicación que llama.

CREATE   proc dbo.CheckForNull @i int 
as
begin
  if @i is null 
    raiserror('The value for @i should not be null', 15, 1) -- with log 

end
GO

Entonces llama:

exec dbo.CheckForNull @i = 1 

o

exec dbo.CheckForNull @i = null