SQL Server I have a datawarehouse problem with the fact and dimension table

kqhtkvqz  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(107)

I have a dimensions table invoices and a fact table

I can see my invoices in dimension invoice but it won't show up in the Fact table. The Fact table is connected to the dimensions table invoice with a foreign key invoice_id. But it's still not showing me the invoice

How can I fix this problem? Can someone help?

Thank you

SELECT [Id] ,[Land] ,[Firm] ,[Magazijn] ,[year] ,[Invoice number] ,[Checksum] ,[LastModifiedDate] 
FROM [DataWarehouse].[dbo].[Dim_Invoices] 
where Invoice number = 6451847

Here is get no invoice for this number

SELECT [Id] ,[Invoice_id],[Land] ,[Firm] ,[Magazijn] ,[year] ,[Invoice number] ,[Invoice_Date] ,[LastModifiedDate] 
FROM [DataWarehouse].[dbo].[FACT] 
where Invoice number = 6451847

Here it shows the invoice number (note Invoice_ID is the FK)

pdtvr36n

pdtvr36n1#

You need to try something like this:

I am not sure why you have the fields in the fact table that you do as they are duplicated in the dimension. What are your measures?

SELECT ft.[Id] 
, ft.[Invoice_id]
, ft.[Land] 
, ft.[Firm] 
, ft.[Magazijn]
, ft.[year] 
, ft.[Invoice number] 
, ft.[Invoice_Date]
, ft.[LastModifiedDate]
, iv.[Id] 
, iv.[Land] 
, iv.[Firm]
, iv.[Magazijn]
, iv.[year] 
, iv.[Invoice number] 
, iv.[Checksum] 
, iv.[LastModifiedDate] 
FROM [DataWarehouse].[dbo].[FACT] ft
JOIN [DataWarehouse].[dbo].[Dim_Invoices] iv ON iv.id = ft.Invoice_id
where iv.[Invoice number] = 6451847

相关问题