sql - SAP B1 Query Returns "Must declare scalar variable " error -
i attempting create drop down menu limit query results item buyer following sql code. however, keep getting error stating need declare scalar variable @itembuyer, despite fact declared , set in code. declare @itembuyer varchar(30) set @itembuyer= /* t3.ownercode */ '[%1]' declare @sql varchar(max) set @sql = 'select t3.[docnum] docnumber, t3.[cardcode] vendorcode, t3.[cardname] vendorname, t3.ownercode buyerid, t2. [itemcode] itemno, t2.[u_cpm_legitemno] legacyitemnumber, t2. [dscription] itemdescription, t2.[u_cpm_confdate] poconfirmdate, t2.[opencreqty] creditmemoamount [dbo].[oitg] t0 , [dbo]. [oitm] t1 inner join [dbo].[por1] t2 on t2.[itemcode] = t1. [itemcode] inner join [dbo].[opor] t3 on t3.[docentry] = t2. [docentry] (t2.[opencreqty] > (0 ) ) , (t2.[u_cpm_confdate] null ) , (t3.[ownercode] = @itembuyer)' exec(@sql) i tried declaring , setting variable below: declare @item...