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?