Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello All ,

Here is my requirement ,

I have below tables in my OLTP database.

Employee
ID BIGINT
Name NVARCHAR

Leaves
EmpId BIGINT
Days NVARCHAR
LeaveType NVARCHAR [Exp SL,CL,PL,ML]

and from the above data we are builing below reports

EmpID EmpName LeaveDays
01 ABC 23
02DEF 25





EmpidEmpNameSLCLPL
01ABC10130
02DEF2005




Please let me know how can I build Fact and Dimenstion table and how can I use SSAS to build the cube.
Posted
Updated 14-Mar-12 0:47am
v5

1 solution

If just to create new dimension/fact tables probably archiving the @Employee and @Leaves. It's possible to make it manually:

SQL
DIMENSION_1	=	EMPLOYEE:
	DIMID	BIGINT;
	ID	BIGINT;
	NAME	NVARCHAR

DIMENSION_2	=	LEAVE
	DIMID	BIGINT
	TYPE	NVARCHAR

FACT_TABLE	=	FACT TABLE
	[Key: DIMENSION_1.DIMID] [Key: DIMENSION_2.DIMID] [Days - NUMBER];



Then fill the tables above and recreate foreign key constraints:
SQL
INSERT INTO DIMENSION_1 (DIMID, ID, NAME)
SELECT ROW_NUMBER() OVER (ORDER BY ID), ID, NAME
FROM
(
	SELECT
		ID, MAX(NAME) NAME
	FROM
		Employee
	GROUP BY
		ID
)


INSERT INTO DIMENSION_2 (DIMID, TYPE)
SELECT ROW_NUMBER() OVER (ORDER BY TYPE), TYPE
FROM
(
	SELECT
		DISTINCT LeaveType TYPE
	FROM
		Leaves
)


INSERT INTO FACT_TABLE (KEY_1, KEY_2, DAYS)
SELECT
	DA.DIMID, DB.DIMID, SUM (CONVERT(BIGINT, B.DAYS)) DAYS
FROM
	Employee A,
	Leaves	B,
	DIMENSION_1	DA,
	DIMENSION_2	DB
WHERE
	A.ID = B.EmpId /*(+)*/
	AND A.ID = DA.ID
	AND B.LeaveType = DB.TYPE
GROUP BY
	DA.DIMID, DB.DIMID


SSAS: probably it's possible to create a new cube defining it's attributes as already processed objects.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900