0

I need to put into the variable @REGIMECASAM, the value that is in the REGIMECASAM field, of the COMPLEMENT table, of the bank FIRMAS (Firebird).

The linked server for the FIRMAS database is working perfectly, but the variable @REGIMECASAM remains empty after the EXEC runs.

Note that when I execute the select with the content of @QUERYTOTAL manually, no errors occur, and the SELECT result is correct, and it has the value 3 as the content of the REGIMECASAM field.

This is the code:

DECLARE @REGIMECASAM INT

DECLARE @OPENQUERY nvarchar (1000), @TSQL nvarchar (1000), @LinkedServer nvarchar (1000) SET @LinkedServer = '[SIGNALS]'

SET @OPENQUERY = 'SELECT REGIMECASAM FROM OPENQUERY (' + @LinkedServer + ',' ''

SET @TSQL = 'SELECT REGIMECASAM FROM COMPLEMENT WHERE LINK =' + CAST (@ CODEID AS VARCHAR (6)) + '' ')'

SET @QUERYTOTAL = @ OPENQUERY + @ TSQL

EXEC sp_executesql @QUERYTOTAL, N '@ REGIMECASAM INT out', @REGIMECASAM OUT

SELECT @REGIMECASAM The Outputs

Can someone help me?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Why do you mention `REGIMEASAM` twice as output parameter when calling `EXEC` ? Also, why do you have a space between the parameter literal `@` and the variable name? – ironstone13 Jul 30 '17 at 19:28
  • 1
    Does [this](https://stackoverflow.com/questions/803211/how-to-get-sp-executesql-result-into-a-variable?rq=1) from the **Related** links on the right side of the page help? – HABO Jul 30 '17 at 21:28
  • The problem was solved ! – Paulo Miranda Jul 30 '17 at 23:19

1 Answers1

0

The problem was solved !

I changed the line below:

SET @OPENQUERY = 'SELECT REGIMECASAM FROM OPENQUERY (' + @LinkedServer + ',' ''

for:

SET @OPENQUERY = 'SELECT @REGIMECASAM= REGIMECASAM FROM OPENQUERY (' + @LinkedServer + ',' ''