declare @company_branch_id uniqueidentifier = 'd3534ff2-b2b2-473f-9be1-e03069bf5c87'
declare @dateFrom date = '10/8/2013'
declare @dateTo date = '11/9/2013'
DECLARE @tbl TABLE(
tbl_Ref varchar(50)
, Reference varchar(100)
, customer_branch_id uniqueidentifier
, trans_date datetime
, duedate datetime
, Charge decimal(18,4)
, Credits decimal(18,4)
, Allocated decimal(18,4)
, Outstanding decimal(18,4)
, pay_amount decimal(18,4))
Insert into @tbl
Exec [dbo].[usp_getCustomerBalanceRpt] @company_branch_id, @dateFrom, @dateTo
UPDATE @tbl
SET trans_date = (SELECT tbl_Rental_InvoiceMaster.Date
FROM tbl_Rental_InvoiceMaster
INNER JOIN @tbl ON @tbl.Reference = tbl_Rental_InvoiceMaster.Reference
WHERE tbl_Rental_InvoiceMaster.Reference= @tbl.Reference
AND @tbl.tbl_Ref='Rental Invoice')
SELECT * FROM @tbl
@company_branch_id、@dateFrom、@dateTo 是传递给 sp 的参数。执行上述代码时,附近显示ERROR
INNER JOIN @tbl ON @tbl.Reference = tbl_Rental_InvoiceMaster.Reference
WHERE tbl_Rental_InvoiceMaster.Reference= @tbl.Reference
AND @tbl.tbl_Ref='Rental Invoice'
作为'Must declare the scalar variable "@tbl".'