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 @itembuyer varchar(30) = /* t3.[ownercode] */ '[%0]' 

but error stating syntax wrong, through variable returns correct value. im little stuck here. can me out.

thanks,

krys

i rewrite query this:

/*select [dbo].[opor] p1*/ declare @itembuyer int /* */ set @itembuyer = /* p1.ownercode */ '[%0]'   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].[por1] t2   inner join [dbo].[opor] t3 on t3.[docentry] = t2.[docentry] t2.[opencreqty] > 0  , t2.[u_cpm_confdate] null  , t3.[ownercode] = @itembuyer 

i still can't manage remember dynamic syntax query, have use link every single time want it: http://www.clientsfirst-us.com/blog/sap/sap-business-one/user-defined-prompts-in-sap-business-one-queries/

notice, also, got rid of couple tables weren't using in select or where statements. it's not going make big of difference in query speed, makes cleaner. (i cleaned formatting put in favorite style, that's not strictly necessary)


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -