fboehlandt
Registered User.
- Local time
- Today, 23:01
- Joined
- Sep 5, 2008
- Messages
- 90
Hi everyone,
I have the following three tables:
Table Assets
Code AUM_Date1 AUM_Date2 ...AUM_Date200
1001
1002
...
7000
this table contains the assets-under-management (AUM) for 6000 investment funds for 200 different months (i.e. 1200000 obs)
Table Returns
Code ROI_Date1 ROI_Date2 ... ROI_Date200
1000
1001
...
7000
this table contains the return-on-investments (ROI) for 6000 investment funds for 200 different months (i.e. 1200000 obs)
Table Information
Code Strategy Leverage
1001
1002
...
7000
this table contains additional information on 6000 investment funds with respect to investment strategy (30 to choose from) and leverage(yes/no)
The tables 'Assets' as well as 'Returns' have separate dates as separate fields (i.e. they are not normalized), which is obviously not ideal. In the example of the 'Assets' table it should look as follows:
Table Asset(revised)
Code Date Value
1001 Date1 AUM1
1001 Date2 AUM2
...
1001 Date200 AUM200
1002 Date1 AUM1
1002 Date2 AUM2
...
1002 Date200 AUM200
mutatis mutandi for all funds up to 6000
Combining the information contained in all three tables it should look something like this:
Query Result
Code Strategy Leverage Date Value Type
1001 xyz yes/no Date1 AUM1 AUM
1001 xyz yes/no Date1 ROI1 ROI
1001 xyz yes/no Date2 AUM2 AUM
1001 xyz yes/no Date2 ROI2 ROI
...
1001 xyz yes/no Date200 AUM200 AUM
1001 xyz yes/no Date200 ROI200 ROI
1002 xyz yes/no Date1 AUM1 AUM
1002 xyz yes/no Date1 ROI1 ROI
1002 xyz yes/no Date2 AUM2 AUM
1002 xyz yes/no Date2 ROI2 ROI
...
1002 xyz yes/no Date200 AUM200 AUM
1002 xyz yes/no Date200 ROI200 ROI
etc.
I have come up with the following query to achieve just that:
Note that 'MM/DD/YYYY' is the manually entered date for the specific observation
Which works fine for smaller samples with a low number of dates considered. Eventually, the query restrictions with respect to max parameters kick in (I assume). So here are my questions:
1. Is there a way to streamline the above?
2. Is there a workaround for the parameter restrictions if not?
3. Is there a query/code snippet for VBA that can be used to create a normalized table (in the event that the sql is not possible)
Please note that I run the query as part of OLE DB query in Excel (importing from Access) where the above query is the command text. Thus, the query should ideally com in one piece. Also, there are some additional components to the real query that I ommitted for simplicity's sake that roughly double the required UNION statements. Any help with this is greatly appreciated. Thanks in advance...
I have the following three tables:
Table Assets
Code AUM_Date1 AUM_Date2 ...AUM_Date200
1001
1002
...
7000
this table contains the assets-under-management (AUM) for 6000 investment funds for 200 different months (i.e. 1200000 obs)
Table Returns
Code ROI_Date1 ROI_Date2 ... ROI_Date200
1000
1001
...
7000
this table contains the return-on-investments (ROI) for 6000 investment funds for 200 different months (i.e. 1200000 obs)
Table Information
Code Strategy Leverage
1001
1002
...
7000
this table contains additional information on 6000 investment funds with respect to investment strategy (30 to choose from) and leverage(yes/no)
The tables 'Assets' as well as 'Returns' have separate dates as separate fields (i.e. they are not normalized), which is obviously not ideal. In the example of the 'Assets' table it should look as follows:
Table Asset(revised)
Code Date Value
1001 Date1 AUM1
1001 Date2 AUM2
...
1001 Date200 AUM200
1002 Date1 AUM1
1002 Date2 AUM2
...
1002 Date200 AUM200
mutatis mutandi for all funds up to 6000
Combining the information contained in all three tables it should look something like this:
Query Result
Code Strategy Leverage Date Value Type
1001 xyz yes/no Date1 AUM1 AUM
1001 xyz yes/no Date1 ROI1 ROI
1001 xyz yes/no Date2 AUM2 AUM
1001 xyz yes/no Date2 ROI2 ROI
...
1001 xyz yes/no Date200 AUM200 AUM
1001 xyz yes/no Date200 ROI200 ROI
1002 xyz yes/no Date1 AUM1 AUM
1002 xyz yes/no Date1 ROI1 ROI
1002 xyz yes/no Date2 AUM2 AUM
1002 xyz yes/no Date2 ROI2 ROI
...
1002 xyz yes/no Date200 AUM200 AUM
1002 xyz yes/no Date200 ROI200 ROI
etc.
I have come up with the following query to achieve just that:
Code:
SELECT Information.Code, Information.Strategy, Information.Leverage, 'MM/DD/YYYY' As Date, Return.ROI_Date1 As Value, 'ROI'As Type
FROM Information INNER JOIN Return ON Information.Code = Return.Code
UNION
SELECT Information.Code, Information.Strategy, Information.Leverage, 'MM/DD/YYYY' As Date, Return.AUM_Date1 As Value, 'AUM'As Type
FROM Information INNER JOIN Assets ON Information.Code = Assets.Code
UNION
SELECT Information.Code, Information.Strategy, Information.Leverage, 'MM/DD/YYYY' As Date, Return.ROI_Date2 As Value, 'ROI'As Type
FROM Information INNER JOIN Return ON Information.Code = Return.Code
UNION
SELECT Information.Code, Information.Strategy, Information.Leverage, 'MM/DD/YYYY' As Date, Return.AUM_Date2 As Value, 'AUM'As Type
FROM Information INNER JOIN Assets ON Information.Code = Assets.Code
...
SELECT Information.Code, Information.Strategy, Information.Leverage, 'MM/DD/YYYY' As Date, Return.ROI_Date200 As Value, 'ROI'As Type
FROM Information INNER JOIN Return ON Information.Code = Return.Code
UNION
SELECT Information.Code, Information.Strategy, Information.Leverage, 'MM/DD/YYYY' As Date, Return.AUM_Date200 As Value, 'AUM'As Type
FROM Information INNER JOIN Assets ON Information.Code = Assets.Code;
Which works fine for smaller samples with a low number of dates considered. Eventually, the query restrictions with respect to max parameters kick in (I assume). So here are my questions:
1. Is there a way to streamline the above?
2. Is there a workaround for the parameter restrictions if not?
3. Is there a query/code snippet for VBA that can be used to create a normalized table (in the event that the sql is not possible)
Please note that I run the query as part of OLE DB query in Excel (importing from Access) where the above query is the command text. Thus, the query should ideally com in one piece. Also, there are some additional components to the real query that I ommitted for simplicity's sake that roughly double the required UNION statements. Any help with this is greatly appreciated. Thanks in advance...