Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

francisvandergr
Contributor II

Combine data from 2 databases

I have a question. I have 2 databases with 3 important tables. The tables in the different databases have the same fields. Example:

Database 1: Table GRBK Fields: Number,Year,Period,Amount

Database 2 Table GRBK Fields: Number,Year,Period,Amount

It is possible that both databases have the same data :

Database 1: Table GRBK 2000,2010,9,100

Database 2: Table GRBK 2000,2010,9,100

In Qlikview i need both records. Anybody knows how to combine both records ?

Tags (1)
1 Solution

Accepted Solutions
MVP
MVP

Combine data from 2 databases

Hello Francis and welcome to the Forums,

Do something like the following:

LOAD *; SQL SELECT * FROM Database1; CONCATENATE LOAD *; SQL SELECT * FROM Database2;


Concatenate keyword is not needed when both tables have the same number of fields and fields are named alike. Anyway, I set it here should you have some differences between both tables.

Hope that helps

6 Replies
MVP
MVP

Combine data from 2 databases

Hello Francis and welcome to the Forums,

Do something like the following:

LOAD *; SQL SELECT * FROM Database1; CONCATENATE LOAD *; SQL SELECT * FROM Database2;


Concatenate keyword is not needed when both tables have the same number of fields and fields are named alike. Anyway, I set it here should you have some differences between both tables.

Hope that helps

MVP
MVP

Combine data from 2 databases

Hi

You could do something along these lines:


DATATABLE:
SQL SELECT Number,
Year,
Period,
Amount,
'Database1' AS Source
FROM Database1.GRBK;

CONCATENATE
SQL SELECT Number,
Year,
Period,
Amount,
'Database2' AS Source
FROM Database2.GRBK;


Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable

Combine data from 2 databases

Try something like the following

CONNECTION STRING

Select

Orders_no,
Order_date,
Number,
Year,
Amount,
Period,
'DB1' as MyDatabase,
etc
From db1.scheme.orders_table;

CONCATENATE

CONNECTION STRING

Select

Orders_no,
Order_date,
Number,
Year,
Amount,
Period,
'DB2' as MyDatabase,
etc
From db2.scheme.orders_table;

francisvandergr
Contributor II

Combine data from 2 databases

Thanx to all. Jonathan i use your script. And of course it works. Smiley Happy

francisvandergr
Contributor II

Combine data from 2 databases

Must i close this question on this forum?

MVP
MVP

Combine data from 2 databases

I'd recommed you to do that, so any other user looking for something similar will find the question as solved.

Community Browser