Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DanielGuardia
Frequent Visitor

Oregen de datos SQL con la misma instancia, pero distintas BBDD

Buenas tardes,

 

Me gustaria saber si existe solucion para la siguiente casuistica.

Quiero extraer datos un SQL, en el que tengo informacion de varias empresas contables. El problema es que  cada contabilidad esta guardado en una BBDD diferente, con lo cual no puedo lanzar una consulta de union desde power BI.

Adjunto una captura de pantalla para que vean la situacion.

DanielGuardia_0-1677180447990.png

Se puede hacer de alguna manera la consulta de Union de las distintas contabilidades, para poder tener power bi una unica consulta con los datos de todas las contabilidades.

Gracias de antemano

1 ACCEPTED SOLUTION
DaniGuardia
New Member

Finalmente localice una solucion, lo hago de la siguienet manera desde Power Query

 

let
Origen = Sql.Database("SERVIDOR\INSTANCIA_SQL", "BBDD", [Query="select distinct idempresa from comunidades"]),
idempresas = Table.Column(Origen, "idempresa"),
basesDeDatos = List.Transform(idempresas, each "xxxx_contabilidad_" & Text.From(_)),
CombinarOrigenes = List.Accumulate(
basesDeDatos,
null,
(state, current) => if state = null then
Sql.Database("SERVIDOR\INSTANCIA_SQL", current, [Query="select * from movimientosContables"])
else
Table.Combine({state, Sql.Database("SERVIDOR\INSTANCIA_SQL", current, [Query="select * from movimientosContables"])})
)

in
Origen

 

View solution in original post

3 REPLIES 3
DaniGuardia
New Member

Finalmente localice una solucion, lo hago de la siguienet manera desde Power Query

 

let
Origen = Sql.Database("SERVIDOR\INSTANCIA_SQL", "BBDD", [Query="select distinct idempresa from comunidades"]),
idempresas = Table.Column(Origen, "idempresa"),
basesDeDatos = List.Transform(idempresas, each "xxxx_contabilidad_" & Text.From(_)),
CombinarOrigenes = List.Accumulate(
basesDeDatos,
null,
(state, current) => if state = null then
Sql.Database("SERVIDOR\INSTANCIA_SQL", current, [Query="select * from movimientosContables"])
else
Table.Combine({state, Sql.Database("SERVIDOR\INSTANCIA_SQL", current, [Query="select * from movimientosContables"])})
)

in
Origen

 

Anonymous
Not applicable

-- create a new database to hold the consolidated data
CREATE DATABASE consolidated_data;

-- create a table in the new database to hold the consolidated data
USE consolidated_data;
CREATE TABLE consolidated_table (
id INT,
company_name VARCHAR(50),
accounting_period VARCHAR(10),
balance DECIMAL(10, 2)
);

-- retrieve data from the first accounting database
USE accounting_db1;
SELECT id, company_name, accounting_period, balance
FROM accounting_table
UNION ALL

-- retrieve data from the second accounting database
USE accounting_db2;
SELECT id, company_name, accounting_period, balance
FROM accounting_table
UNION ALL

-- retrieve data from the third accounting database
USE accounting_db3;
SELECT id, company_name, accounting_period, balance
FROM accounting_table

-- insert the combined data into the consolidated table
INSERT INTO consolidated_table (id, company_name, accounting_period, balance)
SELECT id, company_name, accounting_period, balance
FROM (
-- the UNION ALL statement goes here
) AS subquery;

You can Also do this in Power Query editor

Muchas gracias por propuestas, lo pruebo esta tarde a ver si consigo solucionarlo

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.