How to return string value from the stored procedure

后端 未结 3 985
情话喂你
情话喂你 2021-02-12 21:17
Alter procedure S_Comp(@str1 varchar(20),@r varchar(100) out)
as
declare  @str2 varchar(100)
set @str2  =\'welcome to sql server. Sql server is a product of Microsoft\'
         


        
相关标签:
3条回答
  • 2021-02-12 21:38

    You are placing your result in the RETURN value instead of in the passed @rvalue.

    From MSDN

    (RETURN) Is the integer value that is returned. Stored procedures can return an integer value to a calling procedure or an application.

    Changing your procedure.

    ALTER procedure S_Comp(@str1 varchar(20),@r varchar(100) out) as 
    
        declare @str2 varchar(100) 
        set @str2 ='welcome to sql server. Sql server is a product of Microsoft' 
        if(PATINDEX('%'+@str1 +'%',@str2)>0) 
            SELECT @r =  @str1+' present in the string' 
        else 
            SELECT @r = @str1+' not present'
    

    Calling the procedure

      DECLARE @r VARCHAR(100)
      EXEC S_Comp 'Test', @r OUTPUT
      SELECT @r
    
    0 讨论(0)
  • change your

    return @str1+'present in the string' ;
    

    to

    set @r = @str1+'present in the string' 
    
    0 讨论(0)
  • 2021-02-12 21:55

    Use SELECT or an output parameter. More can be found here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=100201

    0 讨论(0)
提交回复
热议问题