Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm currently working on a project of building a data mart using SSIS 2008 r2 from ERP database.

These datamarts will have to be used in every database that has the same structure (same tables/fields).

The problem is that the source table name changes based on the database connected to. But the table structure (metadata) does not change between those environments.

For example,
Database 1 item table name is company_name1$item
Database 2 item table name is company_name2$item

I'm looking for a solution that makes the datamart can be used for both databases.

I did some research; I found that my solution can be like explained in the picture
![enter image description here][1]

As you in the diagram picture, there are steps to follow to build the datamart:

solution diagram image

- To build a datamart, you will to extract the informations and process
them through ETL to have the desired datamart. This procedure needs
to be applied to all databases




- This procedure can be done by a table in the erp database called
object This table has all kind of informations about the database
tables but the most useful fields are table id,table name and company
name

object table image

Now, I want to use this table id, Name Company to select the proper table without having to selected data based on table name but there no linking between object table and other tables, so you kind of need to create a some kind of code or something to be able to create the link.
*In a nut shell, when I want to use package for a databse , I have insert is the company name and the package will be run to fill my datamart.*

As some suggested, I should use a sql procedure of this type



SQL
USE YourDataBaseName;
  CREATE PROCEDURE GetMyData
        @aCompany NVARCHAR(50) = NULL,
        @tbl_ID INT = 0
    AS
        SET NOCOUNT ON;
        DECLARE @tableName NVARCHAR(50)
        DECLARE @aQuery NVARCHAR(4000) 
     
        SELECT @tableName = [Name]
        FROM [object]
        WHERE [Company Name] = @aCompany AND [ID] = @tbl_ID
     
        SET @aQuery = 'SELECT * FROM ' + @tableName
        EXEC(@aQuery)
    GO


Other one which was also interesting, said that SSIS allows for the use of a variable name in your source and destinations. I just simply need to provide the mechanism for making that value change. Perhaps that's a foreach enumerator containing the data flow or a parameter set at run-time.

Both suggested solution are great but still not clear on how to do that , I hope now that I have explained my question, I would get a more specific answer
Posted
Updated 23-Jun-12 9:21am
v7
Comments
Maciej Los 21-Jun-12 18:22pm    
DO you want to achieve something like that:
DECLARE @tableName NVARCHAR(50)
--get table name from table 'object'
SELECT @tableName = [Name] FROM Object WHERE [Company Name] = @aCompany
--now, get data from this table
SELECT * FROM @tableName
???
Angix 23-Jun-12 9:04am    
Thanks for your answer !!I think a stored procedure will help me through this!
I will try it and will feed you back !

I think you are going to need views that return the data you want but are called the same in all database. To help organisation you should put the views in a schema other than dbo.

The only problem with this is crud operations. Are you planning to update the tables?
 
Share this answer
 
Comments
Angix 21-Jun-12 15:43pm    
Thanks for your answer !
if you mean by updating table is adding data to tables on a regular basis then the answer is yes.but,how those view will be linked to object table.I still have no idea how this vue should be like 'coded' ?any help ?
Maciej Los 21-Jun-12 18:25pm    
See my comment to the question. Upgrade your question using "Improve question" button.
db7uk 21-Jun-12 17:10pm    
Have you got a small script output for both tables? I think I get your situation but please expand on what you refer to as object table?
Maciej Los 21-Jun-12 18:24pm    
Agree. We need more details...
Maciej Los 21-Jun-12 18:39pm    
Views... it could works.
My 5!
First of all, read my comment to the question and to the solution1. Probably, you need to create[^] a stored procedure[^] :

SQL
USE YourDataBaseName;

CREATE PROCEDURE GetMyData
    @aCompany NVARCHAR(50) = NULL,
    @tbl_ID INT = 0
AS
    SET NOCOUNT ON;
    DECLARE @tableName NVARCHAR(50)
    DECLARE @aQuery NVARCHAR(4000) 

    SELECT @tableName = [Name]
    FROM [object]
    WHERE [Company Name] = @aCompany AND [ID] = @tbl_ID

    SET @aQuery = 'SELECT * FROM ' + @tableName
    EXEC(@aQuery)
GO
 
Share this answer
 

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



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