I declare a table variable as APTDAPCO
is a user defined type
DECLARE @APTDAPCO APTDAPCO
INSERT INTO @APTDAPCO
SELECT
APTD.APCo,
APTD.Mth,
APTD.APTrans,
APTD.APLine,
APTD.Amount,
APTD.PayType,
APTD.PaidDate,
APCO.RetPayType
FROM
[Viewpoint].[dbo].[APTD] WITH (NOLOCK)
LEFT JOIN
[Viewpoint].[dbo].[APCO] WITH (NOLOCK) ON [APCO].[APCo] = [APTD].[APCo]
WHERE
APTD.APCo = 1
This is in one stored procedure.
When I try to use this table variable in a select statement
SELECT *
FROM HQCO
LEFT JOIN @APTDAPCO ON HQCO.CO = @APTDAPCO.APCo
I keep getting a compilation error in my stored procedure
Msg 137, Level 16, State 1, Procedure lc_PM11127_CommitmentReport_Optimize, Line 80 [Batch Start Line 9]
Must declare the scalar variable "@APTDAPCO".
What am I doing wrong?
DECLARE @APTDAPCO table
(APCO varchar(max), mth varchar(max),
Aptrans varchar(max), apline varchar(max),
Amount float, paytype varchar(max),
Paiddate datetime, retpaytype varchar(max))
Insert into @APTDAPCO
Select APTD.APCo,
APTD.Mth,
APTD.APTrans,
APTD.APLine,
APTD.Amount,
APTD.PayType,
APTD.PaidDate,
APCO.RetPayType
from [Viewpoint].[dbo].[APTD] WITH (NOLOCK)
LEFT JOIN [Viewpoint].[dbo].[APCO] WITH (NOLOCK)
ON [APCO].[APCo] = [APTD].[APCo]
Where APTD.APCo=1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.