Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 14th, 2005, 07:19 AM
Linval Linval is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 1 Linval User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 52 sec
Reputation Power: 0
Select Count(Distinct)

I have an app which allows the user to count records within a database table that matches Criteria that they specify.

The user can select from 3 drop-down list boxes the 'TableName', 'FieldName' and 'Criteria' and also specify a 'Value' within a Textbox.

The App will then Generate a temp stored procedure that generates the required SQL to search the table counting all records where the value of the 'Fieldname' field matches 'Criteria'.

The App returns Both A Gross and Net Totals as shown in the following example SQL:

SELECT @Gross =Count(*) , @Net=Count(DISTINCT Surname + Address1 + Postcode) from myTable
WHERE (Surname='SMITH' and Postcode like 'SE%') OR .....

This all works fine on tables with small number of recs but can be SLOW in returning results wher the table contains Recs between 500,000 and 2 Million Recs.

I Notice that If I Remove the @Net=Count(DISTINCT Surname + Address1 + Postcode) portion of the SQL the results are returned faster.

Is there a way I can SPEED up the Counting of distinct recs for a particular Surname, Address and postcode?

I chose to use a temp stored Proc to generate the sql because I could not find a way of generating the SQL where the table name is passed as a parameter

I am Not sure If I am using the best approach here in order to get the best performance. Advice Appreciated.



Urgent Reply appreciated.


Linval

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Select Count(Distinct)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT