title: better way to assign stored procedures output values from a table select
body: <p>Due to programming language restraints, my ERP system does not allow me to make advanced select queries, that´s why I need to rely on making a stored procedure on SQL Server, calling it from the ERP system and getting the result through an array.</p>
  
  <p>The code belows works ok, but I think it´s not the correct way to assign the values to the output variables... I wanted to assign the output variables directly from the select, without need to make a #temp table... is it possible? or did I make it right?</p>
  
  <p>If the code can be enhanced, I would gracefully accept any suggestions. The objective of the code is call a stored procedure with a RFID tag (read by a RFID card reader) and then get some employee info from another database, from another ERP, on another server (linked through SQL "linked servers")</p>
  
  <pre><code>ALTER procedure [dbo].[KSBValTag] 
  (
  @rfid varchar(20),
  @OUT_NUMCAD varchar(10) OUTPUT,
  @OUT_NOMFUN varchar(50) OUTPUT,
  @OUT_SIT varchar(2) OUTPUT,
  @OUT_CODCCU varchar(5) OUTPUT,
  @OUT_NOMCCU varchar(30) OUTPUT 
  ) as
  
  Begin
  
      set @rfid = SUBSTRING(@rfid, PATINDEX('%[^0]%', @rfid+'.'), LEN(@rfid))
  
      select fun.numcad as Numcad,
      fun.nomfun as Nomefun,
      fun.sitafa as Situacao,
      fun.codccu as CodCCU,
      ccu.nomccu as NomeCCU
      into #temp
      from [vetorh].vetorh.r034fun as FUN
      inner join
      [vetorh].vetorh.r018ccu CCU
      on fun.codccu = ccu.codccu
      where numcad = (select num_cartao from [ksb-app01].topacesso.dbo.Cartoes where CodigoDeBarras = @rfid)
      and tipcol = '1'
  
      set @OUT_NUMCAD = (select Numcad from #temp)
      set @OUT_NOMFUN = (select Nomefun from #temp)
      set @OUT_SIT = (select Situacao from #temp)
      set @OUT_CODCCU = (select CodCCU from #temp)
      set @OUT_NOMCCU = (select NomeCCU from #temp)
  
  End
  </code></pre>