2
I made a Linked of my SQLSERVER
with the FIREBIRD
. But when I pass a variable inside the query to return the amount of record I get the error:
Message 137, Level 15, Status 1, Line 1 Must declare the scalar variable "@Qtdreg".
Script:
DECLARE @LINKED VARCHAR(50)
DECLARE @SQL_LINKED VARCHAR(7000)
DECLARE @OPENQRY VARCHAR(7000)
DECLARE @QtdReg VARCHAR(700)
declare @codpro varchar(10)
SET @codpro = '1000'
SET @LINKED = 'Mylinked'
SET @SQL_LINKED = 'SELECT count(1) as total FROM produto i WHERE CAST(I.codigoref AS VARCHAR(10)) = '''''+@CodPro+''''' and i.caixa=201 '
SET @OPENQRY = ' SELECT @QtdReg = ItemFT.total FROM Openquery('+@LINKED+', '''+@SQL_LINKED+''') ItemFT'
EXECUTE (@OPENQRY)
SELECT @QTDREG
I tried to use SP_executesql
error also occurs. What I am doing wrong?
I think the problem there is that in the scope of
EXECUTE(@OPENQRY)
the variable@QtdReg
is not declared.– cantoni