执行SQL语句时遇到问题

时间:2014-03-26 16:46:53

标签: sql-server-2005

我不断得到一个" IDENTIFIER预期"尝试执行以下代码时出错。任何人都可以帮忙吗?

SELECT @remotesql = '
SELECT A.AS_OF_DATE, A.ACCOUNT_NUMBER, A.MARKET_VALUE, A.CUSIP, A.SECURITY_TYPE, C.ADMIN_OFFICER, C.BRANCH_NUMBER, 
       D.TICKER_SYMBOL, D.SUB_CLASS,
CASE
    WHEN C.ACCT_SUB_TYPE = 126 OR C.ACCT_SUB_TYPE = 128 OR C.ACCT_SUB_TYPE = 130 OR
         C.ACCT_SUB_TYPE = 131 THEN ''AMGIC/Outside Custodian''
    WHEN B.AUTHORITY = ''N'' THEN ''CUSTODY''
    ELSE ''AUM''
END AS ACCOUNT_TYPE
FROM [DPG].[dbo].[AddvHoldings] AS A
LEFT JOIN SQLUser.AC_IV AS B ON A.ACCOUNT_NUMBER = B.ACCOUNT_NUMBER
LEFT JOIN SQLUser.AC_BI AS C ON A.ACCOUNT_NUMBER = C.ACCOUNT_NUMBER
LEFT JOIN Addv.Holdings AS D ON A.ACCOUNT_NUMBER = D.ACCOUNT_NUMBER AND A.CUSIP = D.CUSIP_NUMBER
'

SELECT @localsql  = 'select * from openquery (TRP, ' +
    dbo.quotestring(@remotesql) + ')'

SELECT @insertsql = 'INSERT INTO #1Holdings'

SET @insertsql = @insertsql + ' ' + @localsql


EXEC(@insertsql)

0 个答案:

没有答案