﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Customery Survey Query with no Duplicates / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 26 May 2013 01:40:45 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Customery Survey Query with no Duplicates</title><link>http://www.sqlservercentral.com/Forums/Topic1379568-391-1.aspx</link><description>Done the job nicely thanks.Have noted the feedback around presenting a query and will incorporate into future posts.Cheers</description><pubDate>Thu, 01 Nov 2012 21:27:53 GMT</pubDate><dc:creator>Dat120Y</dc:creator></item><item><title>RE: Customery Survey Query with no Duplicates</title><link>http://www.sqlservercentral.com/Forums/Topic1379568-391-1.aspx</link><description>Without something to test this against and using Dwain's tip on the row_number, the following may do what you want[code="sql"];WITH NewIDAllRecords AS (	SELECT 		jobDB.num AS JobNumber, 		DateAdd(minute, 570, jobDB.entered) AS CreatedDate, 		DateAdd(minute, 570, jobDB.closed) AS ClosedDate, 		person.uniqueId AS UserID,		NEWID() AS Random		FROM jobDB 		LEFT OUTER JOIN person ON jobDB.contactId=person.personID	WHERE jobDB.status=N'Closed' 		AND DateAdd(minute, 570, jobDB.entered) &amp;gt;= DATEADD(d, -28, GETDATE()) 		AND DateAdd(minute, 570, jobDB.closed) &amp;gt;= DATEADD(d, -7, GETDATE())		AND person.uniqueId IS NOT NULL	),	SequenceAllUserRecords AS (	SELECT		ROW_NUMBER() OVER (PARTITION BY UserID ORDER BY Random) AS Seq,		JobNumber, CreatedDate, ClosedDate, UserID, Random	FROM NewIDAllRecords	)SELECT TOP 50	JobNumber, CreatedDate, ClosedDate, UserIDFROM SequenceAllUserRecordsWHERE Seq = 1ORDER BY Random[/code]</description><pubDate>Thu, 01 Nov 2012 19:47:08 GMT</pubDate><dc:creator>mickyT</dc:creator></item><item><title>RE: Customery Survey Query with no Duplicates</title><link>http://www.sqlservercentral.com/Forums/Topic1379568-391-1.aspx</link><description>[quote][b]T_Dot_Geek (10/31/2012)[/b][hr]Please follow below article helps you how to provide more clarity for your posthttp://www.sqlservercentral.com/articles/Best+Practices/61537/[/quote]We're asking the OP to make it easier for us so let's make it easy for him by providing a clickable link, shall we?[url]http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]</description><pubDate>Wed, 31 Oct 2012 22:57:47 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>RE: Customery Survey Query with no Duplicates</title><link>http://www.sqlservercentral.com/Forums/Topic1379568-391-1.aspx</link><description>Please follow below article helps you how to provide more clarity for your posthttp://www.sqlservercentral.com/articles/Best+Practices/61537/</description><pubDate>Wed, 31 Oct 2012 22:50:58 GMT</pubDate><dc:creator>T_Dot_Geek</dc:creator></item><item><title>RE: Customery Survey Query with no Duplicates</title><link>http://www.sqlservercentral.com/Forums/Topic1379568-391-1.aspx</link><description>Take a look at using ROW_NUMBER() in MS BOL.If you can't figure it out post some DDL and sample data (consumable form) where your query would return duplicates.  Identify which duplicates you'd like removed.With that someone can provide you a fully tested solution.</description><pubDate>Wed, 31 Oct 2012 19:11:23 GMT</pubDate><dc:creator>dwain.c</dc:creator></item><item><title>Customery Survey Query with no Duplicates</title><link>http://www.sqlservercentral.com/Forums/Topic1379568-391-1.aspx</link><description>Hi,I'm trying to build a customer survey query of 50 random jobs where no customer (UserID) appears more than once. I've played around with DISTINCT and GROUP BY but either get an error or still get duplicates. What can I do to achieve this?[code="sql"]SELECT TOP 50    jobDB.num AS JobNumber,     DateAdd(minute, 570, jobDB.entered) AS CreatedDate,     DateAdd(minute, 570, jobDB.closed) AS ClosedDate,     person.uniqueId AS UserID,    NEWID() AS Random    FROM jobDB     LEFT OUTER JOIN person ON jobDB.contactId=person.personID    WHERE jobDB.status=N'Closed'     AND DateAdd(minute, 570, jobDB.entered) &amp;gt;= DATEADD(d, -28, GETDATE())     AND DateAdd(minute, 570, jobDB.closed) &amp;gt;= DATEADD(d, -7, GETDATE())    AND person.uniqueId IS NOT NULL    ORDER BY Random[/code]Rgds</description><pubDate>Wed, 31 Oct 2012 17:32:26 GMT</pubDate><dc:creator>Dat120Y</dc:creator></item></channel></rss>