[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

03/17/2008 at 01:46PM PDT, ID: 23248426
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

summarize, remove duplicates

Asked by SweatCoder in MS SQL Server

This question is related to:

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_23243164.html

In the last post I got a good solution to my problem UNTIL I added more cols to the select, which forced me to add the same cols to group by, at which time I started getting "duplicate" records again. I'm defining duplicate as seeing the same CustID two or more times in a single resultset.

In the resultset below (extracted from a larger resultset), there are 4 records, but I only want 1 record. I want the record that has the latest datestamp in EITHER AddressCreate or PhoneCreate. That is the ideal. If that is really tough to do, then just the latest in either column (not compared across columns). But the most important thing is that (1) I only get a single record per custid and (2) I get the latest record per AddressCreate or PhoneCreate. And if I could get the latest comparing those 2 columns with each other, that would be the ultimate solution.

My latest query, based on previous solution, but with added SELECT items (giving me duplicates) is:

SELECT top 100 m.CustID, MAX(a.dtStamp) AS AddressCreate, MAX(p.dtStamp) AS PhoneCreate, m.FirstName, m.LastName, a.Address1, a.City, a.State, a.Zip, p.PhoneNumber AS Phone
FROM Member m (nolock)
JOIN Address a (nolock)
ON m.CustID = a.CustID
JOIN Phone p (nolock)
ON m.CustID = p.CustID
JOIN Customer c (nolock)
ON c.CustID = m.CustID
WHERE (c.CompanyID = 1 OR c.CompanyID IS NULL)
AND m.LastName = 'Foo'
AND m.Active = 1
AND m.[Primary] = 1
GROUP BY m.CustID, m.LastName, m.FirstName, a.Address1, a.City, a.State, a.Zip, p.PhoneNumber
ORDER BY m.CustID
1:
2:
3:
4:
5:
6:
CustID	AddressCreate     PhoneCreate	FN       LN      ADDR	         City	ST	Zip	Phone
==========================================================================================================
00041646	2005-05-01 00:23	2005-04-30 22:34	Jill   	Foo     47 Foobar AVE.	Ina	AK	45590	5872853239
00041646	2005-05-01 00:23	2005-04-30 22:24	Jill  	Foo     47 Foobar AVE.	Ina	AK	45590	6054348877
00041646	2005-04-30 22:55	2005-04-30 22:34	Jill   	Foo     91 Zoobar LN.	DNP	HI	77742	5872853239
00041646	2005-04-30 22:55	2005-04-30 22:24	Jill   	Foo     91 Zoobar LN.	DNP	HI	77742	6054348877
[+][-]03/17/08 02:10 PM, ID: 21146177

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/17/08 02:11 PM, ID: 21146189

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/17/08 02:16 PM, ID: 21146244

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/17/08 02:18 PM, ID: 21146259

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/17/08 02:50 PM, ID: 21146492

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: BriCrowe
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03/17/08 02:55 PM, ID: 21146535

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/18/08 09:58 AM, ID: 21153172

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/18/08 11:30 AM, ID: 21154267

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03/18/08 12:59 PM, ID: 21155130

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/23/08 05:40 AM, ID: 21845516

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06/27/08 06:58 PM, ID: 21888841

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091028-EE-VQP-87 / EE_QW_EXPERT_20070906