LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get OUTPUT and RETURN parameters from a stored procedure

Solved!
Go to solution

I have a stored procedure (MS SQL Server 2008 R2) like the following example.

 

Using Database Connectivity I can get the OUTPUT parameters but I can't get de RECORDSET DATA and de RETURN value.

 

Does anybody knows how to do that?

 

CREATE PROCEDURE [dbo].[TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR(20), @STATUS INT OUTPUT, @ERRO NVARCHAR(500) OUTPUT)

AS

BEGIN     
  DECLARE @TABLE TABLE(CODIGO INT, DESCRICAO VARCHAR(30))

  INSERT INTO @TABLE VALUES (51, 'A')     
  INSERT INTO @TABLE VALUES (52, 'B')

  INSERT INTO @TABLE VALUES (53, 'C')

  SELECT * FROM @TABLE

  SET @STATUS = 1

  SET @ERRO = 'Nenhum erro!'

  RETURN 0

END

0 Kudos
Message 1 of 3
(3,437 Views)

Now I could get the RETURN, but I still can't get the RECORDSET DATA (returns empty but shouldn't be). Please anybody help me.

0 Kudos
Message 2 of 3
(3,430 Views)
Solution
Accepted by topic author fabian.oberdiek

I finaly found what was wrong... It was necessary an only aditional line in the stored procedure. It should be like that:

 

CREATE PROCEDURE [dbo].[TS_Teste] (@T057_S_NOMEMAQUINA VARCHAR(20), @STATUS INT OUTPUT, @ERRO NVARCHAR(500) OUTPUT)

AS

BEGIN    
  SET NOCOUNT ON;                                                                                               -- NEW LINE!!!

  DECLARE @TABLE TABLE(CODIGO INT, DESCRICAO VARCHAR(30))

  INSERT INTO @TABLE VALUES (51, 'A')    
  INSERT INTO @TABLE VALUES (52, 'B')

  INSERT INTO @TABLE VALUES (53, 'C')

  SELECT * FROM @TABLE

  SET @STATUS = 1

  SET @ERRO = 'Nenhum erro!'

  RETURN 0

END

0 Kudos
Message 3 of 3
(3,417 Views)