2

I would like to combine these queries:

UPDATE T1
SET Opening_date = T2.Opening_date
FROM FactTransaction T1
INNER JOIN DimStore T2 ON T1.cod_Store = T2.Cod_StoreKey

and

UPDATE FactTransaction
SET ORDINAL = DATEDIFF(DAY, Opening_Date, DATE)

In order to avoid insert the field Opening_date in my fact table. I don't know how to do it just with a query.

1 Answer 1

3
UPDATE T1 SET 
Opening_date = T2.Opening_date, 
ORDINAL = DATEDIFF(DAY, T2.Opening_Date, T1.DATE) 
FROM FactTransaction T1 
INNER JOIN DimStore T2 ON T1.cod_Store = T2.Cod_StoreKey;

...if I understand you correctly.

Edit: Ok, just go with:

UPDATE T1 SET 
ORDINAL = DATEDIFF(DAY, T2.Opening_Date, T1.DATE) 
FROM FactTransaction T1 
INNER JOIN DimStore T2 ON T1.cod_Store = T2.Cod_StoreKey;
2
  • yeah, the thing is that my fact table does not have the field "opening_date" which is on DimStore. So I want to get the datediff between Date (Factable) and Opening_date (DimStore)
    – Miguel
    Commented Sep 23, 2015 at 10:55
  • Edited... Try that.
    – Rob Farley
    Commented Sep 23, 2015 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.