Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Appending Results

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-03-14 : 11:57:05
Hey Guys

Your well

I need some assistance

I have created the following query

SELECT 'Total Outlets',
count(FDMSAccountNo) as Total
FROM [FDMS].[dbo].[Dim_Merchant_Log_All]
where FDMSAccountNo <> Chain_Chain_No
and FDMSAccountNo <> Corp_Chain_No
and FDMSAccountNo <> Agent_Chain_No
and Period = 201401

Which produces the following
(No column name) Total
Total Outlets 172787

I have also created the following query

SELECT 'Total Outlets',
count(distinct(dla.FDMSAccountNo)) as Non_ISO_Total
FROM Dim_Merchant_Log_All DLA
INNER JOIN Dim_Outlet ON DLA.Agent_Chain_No = Dim_Outlet.Agent_Chain_No
where DLA.FDMSAccountNo <> DLA.Chain_Chain_No
and DLA.FDMSAccountNo <> DLA.Corp_Chain_No
and DLA.FDMSAccountNo <> DLA.Agent_Chain_No
and ISO_Account = 'N'
and Period = 201401

which produces the following

(No column name) ISO_Total
Total Outlets 71364

What i want to do is attached the total outlets on the ISO total onto the total outlets total

Required results

(No column name) Total ISO_Total
Total Outlets 172787 71364



looking forward to your help

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-03-14 : 13:59:06
Here is one way to do that:
SELECT 'Total Outlets', 
(
SELECT
count(FDMSAccountNo)
FROM [FDMS].[dbo].[Dim_Merchant_Log_All]
where FDMSAccountNo <> Chain_Chain_No
and FDMSAccountNo <> Corp_Chain_No
and FDMSAccountNo <> Agent_Chain_No
and Period = 201401
) AS Total,
(
SELECT
count(distinct(dla.FDMSAccountNo))
FROM Dim_Merchant_Log_All DLA
INNER JOIN Dim_Outlet ON DLA.Agent_Chain_No = Dim_Outlet.Agent_Chain_No
where DLA.FDMSAccountNo <> DLA.Chain_Chain_No
and DLA.FDMSAccountNo <> DLA.Corp_Chain_No
and DLA.FDMSAccountNo <> DLA.Agent_Chain_No
and ISO_Account = 'N'
and Period = 201401
) AS Non_ISO_Total
Go to Top of Page
   

- Advertisement -