Select FN,LN
Group by FN from A
Gives me
Bob
Bob
Tom
Tom
Tom
Bill
Bill
Need to achive output of names not after one another if they are same
name
Bob
Tom
Bill
Bob
Tom
Bob
Bill
Order is not important as long as they dont repaeat same name for next
row
On 21 Dec 2005 13:50:36 -0800, Matt wrote:
>Select FN,LN
>Group by FN from A
>Gives me
>Bob
>Bob
>Tom
>Tom
>Tom
>Bill
>Bill
Hi Matt,
You must have made a mistake in this post. That query can never result
in anything but an error message.
>Need to achive output of names not after one another if they are same
>name
>Bob
>Tom
>Bill
>Bob
>Tom
>Bob
>Bill
>Order is not important as long as they dont repaeat same name for next
>row
Not sure I understand the requirements, but it sounds like a task for
the front end.
If you really want to do this server-side, then please proviude better
specs. Check out www.aspfaq.com/5006.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Since you specify no ORDER BY, SQL Server may return data in any sequence.
To return data in a pseudo random order, you can include ORDER BY NEWID().
> Need to achive output of names not after one another if they are same
> name
> Order is not important as long as they dont repaeat same name for next
> row
Is random order acceptable? In order words, is it ok if 2 or more same
names are consecutive, if only by coincidence?
Hope this helps.
Dan Guzman
SQL Server MVP
"Matt" <metehanIT@.Hotmail.com> wrote in message
news:1135201836.056730.13200@.o13g2000cwo.googlegro ups.com...
> Select FN,LN
> Group by FN from A
> Gives me
> Bob
> Bob
> Tom
> Tom
> Tom
> Bill
> Bill
> Need to achive output of names not after one another if they are same
> name
> Bob
> Tom
> Bill
> Bob
> Tom
> Bob
> Bill
> Order is not important as long as they dont repaeat same name for next
> row
>
|||Pushing those recordsets to another system, system does not allow me to
push smilar account one another.
So i cant push right after another. I need to push different name.
Since there are no other Indicator to differenciate the records
Above query was an example
any idea?
|||As Hugo requested, we really need DDL, a working query and sample to data to
help you out. Presuming that FN is the differentiator, what should be done
when it is impossible to order results to prevent consecutive duplicates?
Consider the following:
Tom
Bob
Tom
Tom
Hope this helps.
Dan Guzman
SQL Server MVP
"Matt" <metehanIT@.Hotmail.com> wrote in message
news:1135260352.114345.114900@.g47g2000cwa.googlegr oups.com...
> Pushing those recordsets to another system, system does not allow me to
> push smilar account one another.
> So i cant push right after another. I need to push different name.
> Since there are no other Indicator to differenciate the records
> Above query was an example
> any idea?
>
|||SQL is almost 300 line thats why could not posted there
This is one something like
SELECT ACCOUNT
FROM TEMP
WHERE CLS_DATE > '12/30/03'
GROUP BY (ACCOUNT)
UNION
SELECT ACCOUNT
FROM TEMP
WHERE CLS_DATE > '12/30/02'
GROUP BY (ACCOUNT)
Gives me result set of
7321234
7321234
7324567
7324567
I need result set to be
7321234
7324567
so on ,, as long as they dont repeat one after another.
Cheers
|||> SQL is almost 300 line thats why could not posted there
300 lines is reasonable. Please post.
I still don't understand your problem. The query you posted will eliminate
duplicate account numbers due to the UNION as illustrated by the example
below.
CREATE TABLE TEMP
(
ACCOUNT int NOT NULL,
CLS_DATE smalldatetime NOT NULL
CONSTRAINT PK_TEMP PRIMARY KEY
(
ACCOUNT,
CLS_DATE
)
)
INSERT INTO TEMP VALUES (7321234, '20021229')
INSERT INTO TEMP VALUES (7321234, '20021230')
INSERT INTO TEMP VALUES (7321234, '20021231')
INSERT INTO TEMP VALUES (7321234, '20031229')
INSERT INTO TEMP VALUES (7321234, '20031230')
INSERT INTO TEMP VALUES (7321234, '20031231')
INSERT INTO TEMP VALUES (7324567, '20021229')
INSERT INTO TEMP VALUES (7324567, '20021230')
INSERT INTO TEMP VALUES (7324567, '20021231')
INSERT INTO TEMP VALUES (7324567, '20031229')
INSERT INTO TEMP VALUES (7324567, '20031230')
INSERT INTO TEMP VALUES (7324567, '20031231')
SELECT ACCOUNT
FROM TEMP
WHERE CLS_DATE > '20031230'
GROUP BY (ACCOUNT)
UNION
SELECT ACCOUNT
FROM TEMP
WHERE CLS_DATE > '20021230'
GROUP BY (ACCOUNT)
Hope this helps.
Dan Guzman
SQL Server MVP
"Matt" <metehanIT@.Hotmail.com> wrote in message
news:1135265718.603518.119100@.g47g2000cwa.googlegr oups.com...
> SQL is almost 300 line thats why could not posted there
> This is one something like
> SELECT ACCOUNT
> FROM TEMP
> WHERE CLS_DATE > '12/30/03'
> GROUP BY (ACCOUNT)
> UNION
> SELECT ACCOUNT
> FROM TEMP
> WHERE CLS_DATE > '12/30/02'
> GROUP BY (ACCOUNT)
> Gives me result set of
> 7321234
> 7321234
> 7324567
> 7324567
> I need result set to be
> 7321234
> 7324567
> so on ,, as long as they dont repeat one after another.
> Cheers
>
|||Thanks Don.
No comments:
Post a Comment