stored procedure returns varchar

后端 未结 3 1440
日久生厌
日久生厌 2020-12-30 09:33

I would like to know if in SQL is it possible to return a varchar value from a stored procedure, most of the examples I have seen the return value is an int.

3条回答
  •  青春惊慌失措
    2020-12-30 09:44

    You will need to create a stored function for that:

    create function dbo.GetLookupValue(@value INT)
    returns varchar(100)
    as begin
      declare @result varchar(100)
    
      select
        @result = somefield
      from 
        yourtable
      where 
        ID = @value;
    
      return @result
    end
    

    You can then use this stored function like this:

    select dbo.GetLookupValue(4) 
    

    Marc

提交回复
热议问题