SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Or help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 01/03/2013 :  06:38:36  Show Profile  Reply with Quote
Hey guys

I need some help

I have a situation where the fdmsaccountno, can have multiple productid associated with it


For eg in the query below

Fdmsaccountno can be have the productid 81 and 83,
However instead of counting 81 and 83 twice, i need it to count it once

Any ideas how this can be achieved

My query is as follows

SELECT 'Visa debit',
Count (distinct Dim_Outlet.FDMSAccountNo)AS [Number]
FROM Dim_Outlet
INNER JOIN stg_FDMS_Card_Entitlements ON Dim_Outlet.FDMSAccountNo = stg_FDMS_Card_Entitlements.FDMSAccountNo
INNER JOIN Dim_Product ON stg_FDMS_Card_Entitlements.[Product Code] = Dim_Product.ProductID
where [ProductID] ='81'
or ProductID ='83'
and [Account_Status]='16'

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/03/2013 :  06:44:41  Show Profile  Reply with Quote
SELECT 'Visa debit',
Count (distinct Dim_Outlet.FDMSAccountNo)AS [Number]
FROM Dim_Outlet
INNER JOIN stg_FDMS_Card_Entitlements ON Dim_Outlet.FDMSAccountNo = stg_FDMS_Card_Entitlements.FDMSAccountNo
INNER JOIN Dim_Product ON stg_FDMS_Card_Entitlements.[Product Code] = Dim_Product.ProductID
where
(
[ProductID] ='81'
or ProductID ='83'
)
and [Account_Status]='16'

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 01/03/2013 :  07:09:52  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Probably simpler

where ProductID in ('81','83')
and [Account_Status]='16'


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000