2014-03-25 101 views
1

在我的过程中,我返回一个int值。存储过程返回空值int

ALTER PROCEDURE [dbo].[GetValue] 
    -- Add the parameters for the stored procedure here 
    @ID int, 

AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    DECLARE @isNew int 
    SET @isNew=0 
    DECLARE @returnedValue int 
    DECLARE @output int 
    SET @returnedValue=[dbo].fn_GetIsNewLecturer(@ID) 


    IF(@returnedValue=0)   
     BEGIN 
      PRINT 'new' 
      EXEC @output=[dbo].[GetNew] @ID 
      SELECT @output 
     END 
    ELSE 
     BEGIN 
      PRINT 'old' 
      EXEC @output=[dbo].[sp_GetOld] @ID 
      SELECT @output 
     END 
     RETURN @output 
END 

它的返回值应该是int。但它返回Nullable int ?.如何改变它为INT enter image description here

回答

1

试试这个:

select [Output] = isnull(@output, 0) 

这也是为什么它应该工作:

declare @i int 

select ni = @i, nni = isnull(@i,0) 
into #t 

select is_nullable, * 
from tempdb.sys.columns 
where [object_id] = object_id(N'tempdb..#t') 

drop table #t