declare @DifferenceTable table ( DataAreaId nvarchar(10) , SalesId nvarchar(50) , InvoiceId nvarchar(50) , ItemId nvarchar(50), InvoiceQty decimal(16,4) , InventoryQty decimal(16,4) ) insert into @DifferenceTable (DataAreaId , SalesId , InvoiceId , ItemId , InvoiceQty , InventoryQty ) select CustInvoiceTrans.DATAAREAID , CustInvoiceTrans.SALESID , CustInvoiceTrans.INVOICEID , CustInvoiceTrans.ITEMID , sum(CustInvoiceTrans.QTY) , 0. as InventoryQty from CustInvoiceTrans with(nolock) group by CustInvoiceTrans.DATAAREAID , CustInvoiceTrans.SALESID , CustInvoiceTrans.INVOICEID , CustInvoiceTrans.ITEMID update @DifferenceTable set InventoryQty = tt.Qty from (select sum(InventTrans.QTY)*-1 as Qty , InventTransOrigin.DATAAREAID , REFERENCEID , InventTrans.INVOICEID , InventTrans.ITEMID from InventTransOrigin left join InventTrans on InventTrans.INVENTTRANSORIGIN = InventTransOrigin.RECID and InventTrans.DATAAREAID = InventTransOrigin.DATAAREAID and InventTrans.ITEMID = InventTransOrigin.ITEMID where REFERENCECATEGORY = 0 group by InventTransOrigin.DATAAREAID , REFERENCEID , InventTrans.INVOICEID , InventTrans.ITEMID ) tt where @DifferenceTable.DataAreaId = tt.DATAAREAID and @DifferenceTable.SalesId = tt.REFERENCEID and tt.INVOICEID = @DifferenceTable.InvoiceId and tt.ITEMID = @DifferenceTable.ItemId select * from @DifferenceTableThe @differencetable isn't recognised as declared, how would I resolve this?
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.