I have following Query which returns Error like 'Must declare the scalar variable "@tbl"'.
declare @tbl as ItemName_Id_Table
,@Entry_Date_To varchar(50) = '2017-10-22'
,@qry nvarchar(max)
set @qry =
'SELECT
tblStockLedger.item_id, tblStockLedger.inward_qty, tblStockLedger.inward_qty2, Fn_StockValue_1.Value
FROM tblStockLedger
LEFT OUTER JOIN dbo.Fn_StockValue('''+@Entry_Date_To+''',@tbl) AS Fn_StockValue_1
ON tblStockLedger.item_id = Fn_StockValue_1.item_id
GROUP BY
tblStockLedger.item_id, tblStockLedger.inward_qty, tblStockLedger.inward_qty2, Fn_StockValue_1.Value'
exec(@qry)
Could any one please explain me how to overcome this Error.