Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. Create Table Gutowski.DIM_TIME(
  2. OrderDate int,
  3. Rok int,
  4. Miesiac varchar(20),
  5. DzienTyg varchar(20),
  6. Dzien varchar(20),
  7. Primary Key(OrderDate)
  8. )
  9.  
  10. CREATE TABLE Gutowski.MONTHS(
  11. "Number" int,
  12. "Month" nvarchar(20)
  13. )
  14.  
  15. Insert into Gutowski.MONTHS
  16. Values (1, 'styczeń'),
  17. (2, 'luty'),
  18. (3, 'marzec'),
  19. (4, 'kwiecień'),
  20. (5, 'maj'),
  21. (6, 'czerwiec'),
  22. (7, 'lipiec'),
  23. (8, 'sierpień'),
  24. (9, 'wrzesień'),
  25. (10, 'październik'),
  26. (11, 'listopad'),
  27. (12, 'grudzień');
  28.  
  29. Create Table Gutowski.DAYS_NAME(
  30. "Number" int,
  31. "Day" nvarchar(20)
  32. )
  33. Insert into Gutowski.DAYS_NAME
  34. Values (2,'poniedziałek'),
  35. (3, 'wtorek'),
  36. (4, 'środa'),
  37. (5, 'czwartek'),
  38. (6, 'piątek'),
  39. (7, 'sobota'),
  40. (1, 'niedziela');
  41.  
  42. Insert into Gutowski.DIM_TIME
  43. Select Distinct OrderDate,
  44. OrderDate/10000,
  45. (Select Gutowski.MONTHS.[Month] From Gutowski.MONTHS Where Gutowski.MONTHS.Number = ((OrderDate % 10000) / 100)),
  46. (Select Gutowski.DAYS_NAME.[Day] From Gutowski.DAYS_NAME Where Gutowski.DAYS_NAME.Number = DATEPART(dw,
  47. CAST((OrderDate/10000) AS VARCHAR(4)) +
  48. RIGHT('0' + CAST(((OrderDate % 10000) / 100) AS VARCHAR(2)), 2) +
  49. RIGHT('0' + CAST((OrderDate % 100) AS VARCHAR(2)), 2))),
  50. (OrderDate % 100)
  51. From Gutowski.FACT_SALES;
  52.  
  53. drop table Gutowski.DAYS_NAME;
  54. drop table Gutowski.MONTHS;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement