我知道这里已经有一些论坛了,但有人可以帮我识别重复项以及如何为列名设置别名吗?我相信底部的左连接是在报表生成器中创建此错误。
SELECT CASE A.DTASERIES
WHEN 2 THEN 'Financial'
WHEN 3 THEN 'Sales'
WHEN 4 THEN 'Purchasing'
WHEN 5 THEN 'Inventory'
WHEN 6 THEN 'Payroll – USA'
WHEN 7 THEN 'Project'
ELSE ''
END AS DTA_Series ,
JRNENTRY AS JournalEntry,
D.ACTNUMST AS AccountNumber,
C.ACTDESCR AS AccountDescription,
A.GROUPID AS DTA_GroupID,
CODEID AS DTA_CodeID,
GROUPAMT ,
CASE
WHEN CODEAMT > 0 THEN CODEAMT
ELSE 0
END AS Debit,
CASE
WHEN CODEAMT < 0 THEN CODEAMT
ELSE 0
END AS Credit,
A.TRXDATE AS TransactionDate,
A.DTAREF AS DTA_Reference,
DTA_GL_Reference ,
A.DOCNUMBR AS OriginalDocumentNumber ,
A.RMDTYPAL ,
CASE PSTGSTUS
WHEN 1 THEN 'Unposted'
WHEN 2 THEN 'Posted'
ELSE ''
END AS DTA_PostingStatus ,
B.DOCNUMBR ,
B.RMDTYPAL ,
POSTDESC AS PostingDescription,
DTAQNTY
FROM dbo.DTA10100 AS A
LEFT OUTER JOIN dbo.DTA10200 AS B ON A.ACTINDX = B.ACTINDX
AND A.DOCNUMBR = B.DOCNUMBR
AND A.DTAREF = B.DTAREF
AND A.DTASERIES = B.DTASERIES
AND A.GROUPID = B.GROUPID
AND A.SEQNUMBR = B.SEQNUMBR
LEFT OUTER JOIN dbo.GL00100 AS C ON A.ACTINDX = C.ACTINDX
LEFT OUTER JOIN dbo.GL00105 AS D ON C.ACTINDX = D.ACTINDX
答案 0 :(得分:2)
SSRS仅在确定数据集的字段时查看列名称,如果SELECT
两个具有相同名称的列来自一个或多个表,则会抛出此错误。
在这种情况下,您的A.RMDTYPAL
子句中有B.RMDTYPAL
和SELECT
,SSRS视为两个RMDTYPAL
列。别名中的一个或两个都会消失。
有关详情,请参阅this similar question。
编辑:(为清楚起见,我只列出了两列)
SELECT
A.RMDTYPAL AS A_RMDTYPAL,
B.RMDTYPAL AS B_RMDTYPAL
FROM dbo.DTA10100 AS A
LEFT OUTER JOIN dbo.DTA10200 AS B ON A.ACTINDX = B.ACTINDX
AND A.DOCNUMBR = B.DOCNUMBR
AND A.DTAREF = B.DTAREF
AND A.DTASERIES = B.DTASERIES
AND A.GROUPID = B.GROUPID
AND A.SEQNUMBR = B.SEQNUMBR
LEFT OUTER JOIN dbo.GL00100 AS C ON A.ACTINDX = C.ACTINDX
LEFT OUTER JOIN dbo.GL00105 AS D ON C.ACTINDX = D.ACTINDX
答案 1 :(得分:2)
以防它帮助其他人:
我在SSRS 2008,SQL Server 2008 R2中遇到了同样的错误。我的存储过程正在执行SELECT * FROM #Results以返回结果集。没有重复的列名称/别名&#39; s。但是,当我将其切换为仅选择所有列而不是*时,它解决了问题。