我有这个代码为我创建一个View,但是它复制了每一行,尽管有DISTINCT命令,还有什么想法?
Use [Table]
Go
CREATE VIEW View_Database_1Mth_Composite AS
SELECT DISTINCT Composite.[DealerCode]
,DealerDetails.[BrandTradeName]
,DealerDetails.[GroupName]
,DealerDetails.[Brand]
,DealerDetails.[RBM]
,Composite.[Ratio_ID]
,CAST (RatioID.[Detail_Desc] AS VARCHAR(8000)) AS Detail_Desc
,Composite.[LineNr]
,Composite.[201301]
,Composite.[201302]
,Composite.[201303]
,Composite.[201304]
,Composite.[201305]
,Composite.[201306]
,Composite.[201307]
,Composite.[201308]
,Composite.[201309]
,Composite.[201310]
FROM [Company_Database].[dbo].[Database_1Mth_Composite$] as Composite
INNER JOIN [Company_Database].[dbo].[Company_DealerDetails] as DealerDetails
ON CAST(Composite.[DealerCode] AS VARCHAR(10))=DealerDetails.[DlrCode]
-- 2nd Join for the Ratio_ID
INNER JOIN [Company_Database].[dbo].[Database_RatioID] as RatioID
ON Composite.[Ratio_ID]=RatioID.[Ratio]
[Company_Database].[dbo].[Database_RatioID] as RatioID
我试过颠倒第一次加入的顺序,但仍然没有运气。
有什么想法吗?
答案 0 :(得分:0)
单个字段不同,导致了这个问题。
感谢大家的帮助,我可能花了太多时间寻找解决方案,并没有看到问题!