HI,
I have his SQL query to get data from two dbs if same server. How to parametrize the db name and pull it in a column (db XXX & db YYY )
use [XXX_PTYLTD]
select
'Actual', glt.accno, acct.[name], acct.reportcode,
acct.balance_sheet_type, glt.subaccno, glt.transdate,
glt.invno, glt.details, glt.batchno, glt.[source],
glt.source_accno, glt.amount, glt.periodno, glt.branchno
from
XXX_PTYLTD.dbo.gltrans glt inner join XXX_PTYLTD.dbo.glaccs acct
on glt.accno = acct.accno
where
--acct.balance_sheet_type=-1 and
transdate between '2021-07-01' and '2022-03-31'
union all
select
'Actual', glt.accno, acct.[name], acct.reportcode,
acct.balance_sheet_type, glt.subaccno, glt.transdate,
glt.invno, glt.details, glt.batchno, glt.[source],
glt.source_accno, glt.amount, glt.periodno, glt.branchno
from
YYY_PTYLTD.dbo.gltrans glt inner join YYY_PTYLTD.dbo.glaccs acct
on glt.accno = acct.accno
where
--acct.balance_sheet_type=-1 and
transdate between '2021-07-01' and '2022-03-31'
The output is like this; but I wan to segregate by database
42015 | Marketing Fees (Recharged) | -1,166.70 | -9,058.50 | -8,850.80 | -8,732.19 | -16,276.60 | -6,992.04 | -13,506.75 | -11,940.60 | -8,164.84 | -84,689.02 |
42016 | Accounting Fee Recharged | -2,997.18 | -5,739.37 | -8,102.20 | -4,206.51 | -10,039.84 | -5,812.67 | -12,495.96 | -2,236.73 | -8,067.32 | -59,697.78 |
Hi Aiyah,
I'm not familiar with SQL, sorry. However, once the query loads, you might be able to get the database name from the Source step of the query. Hope that points you in the right direction.
Mynda