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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 count (distinct _____ )

Author  Topic 

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2010-01-21 : 11:10:58
Trying to run a distinct count for all ID's that have a date in february, and don't have an entry into the last 12 months.

I think I have it setup properly but the number I getting back is too high. Could someone take a peak and let me know if I am doing something wrong?

Thanks



SELECT COUNT(DISTINCT dbo.tblContracts.ClientID) AS NumNewClients
FROM dbo.tblContractDetail INNER JOIN
dbo.tblContracts ON dbo.tblContractDetail.ContractID = dbo.tblContracts.ContractID
WHERE (dbo.tblContracts.ClientID NOT IN
(SELECT DISTINCT clientid
FROM dbo.tblContractDetail INNER JOIN
dbo.tblContracts ON dbo.tblContractDetail.ContractID = dbo.tblContracts.ContractID
WHERE tblcontractdetail.inhomedate BETWEEN DATEADD(day, - 1, '1/21/2010') AND DATEADD(month, - 12, '1/21/2010'))) AND
(dbo.tblContractDetail.FranchiseID = 'mdipho') AND (MONTH(dbo.tblContractDetail.InHomeDate) = 2) AND
(dbo.tblContractDetail.InHomeDate NOT BETWEEN DATEADD(day, - 1, '1/21/2010') AND DATEADD(month, - 12, '1/21/2010'))

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-21 : 11:19:36
between needs the lower value first!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mxfrail
Yak Posting Veteran

84 Posts

Posted - 2010-01-21 : 11:24:10
damn it! knew it was something stupid. thanks.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-21 : 12:05:59
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Aiby
Yak Posting Veteran

71 Posts

Posted - 2010-01-24 : 10:28:25

Did you mean Distinct Count of ID in a Month/Year ?
Better give Table Structure, then One can get understand bit more. Good Luck


quote:
Originally posted by webfred

between needs the lower value first!


No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page
   

- Advertisement -