【问题标题】:Stored procedure returns nullable int存储过程返回可为空的 int
【发布时间】:2014-03-25 10:35:55
【问题描述】:

在我的程序中,我返回一个 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

【问题讨论】:

    标签: entity-framework sql-server-2008 stored-procedures


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      相关资源
      最近更新 更多