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
 Transact-SQL (2000)
 Distinct Count

Author  Topic 

memarcie
Yak Posting Veteran

91 Posts

Posted - 2006-12-19 : 13:38:40
Hi There,
I need to count just the number of claims using this query and not the number of detail lines which is why I am using distinct. This causes the query to run much longer. Any suggestions on how to speed this up?



select
a.proc_date,
a.tax_id,
b.full_name as provider_name,
Sum(c.Charge) Amount_Billed,
Sum(c.price) Amount_Repriced,

Count(distinct a.claim) Total_Count,
'BUILD_STBL_CLAIMS_BY_PROVIDER', --sys_source
getdate() --sys_created

from HMPDW_staging.dbo.master a
join hmpdw_staging.dbo.detail c on a.claim = c.claim and a.version = c.version
and a.source = c.source
left join HMPDW_Staging.dbo.provider b on a.prov_num = b.prov_num
where proc_date >= dateadd(year, -2, getdate())
group by a.proc_date, a.tax_id, b.full_name



Thanks,
Marcie

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-19 : 13:42:58
How much is longer?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

memarcie
Yak Posting Veteran

91 Posts

Posted - 2006-12-19 : 14:01:47
twice as long. It takes ~21 minutes if I remove the distinct and ~45 with
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-19 : 14:05:04
How many records each are there in the three tables?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

memarcie
Yak Posting Veteran

91 Posts

Posted - 2006-12-19 : 14:15:24
a - 19mil
b - 45mil
c - 116,000
Go to Top of Page

memarcie
Yak Posting Veteran

91 Posts

Posted - 2006-12-19 : 20:00:13
Did anyone have an way to speed this up or am I out of luck because there are so many records in the tables?

Thanks,
Marcie
Go to Top of Page
   

- Advertisement -