Re: Alphabetizing a Comma Delimited String

From: Dr. StrangeLove (steve.nospam._at_rac4sql.net)
Date: 02/28/04


Date: Sat, 28 Feb 2004 10:36:30 -0500


"Aaron Bertrand [MVP]" <aaron@TRASHaspfaq.com> wrote in message
news:ujuNpQW$DHA.3352@TK2MSFTNGP09.phx.gbl...
> Simulate an array, stuff it into a table, and then use order by. Use the
> client to put it back into a comma-delimited string.
>
> (See http://www.aspfaq.com/2248 for ideas and links about using
split()-like
> functionality to break up a string and store it in table form.)
>
> Better yet, store each item in a table rather than having this grotesque
> non-relational string in the first place. You will probably get great
> efficiencies in storage, since you could use a code or TINYINT
> representation.

One *wonders* why this functionality is not in the server engine.

Now here's something *wonder-full*.It's from MySql v4.1:

----------------------------------------------------------------------------
----------------------
GROUP_CONCAT(expr)
Full syntax:
GROUP_CONCAT([DISTINCT] expr [,expr ...]
             [ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC]
[,col ...]]
             [SEPARATOR str_val])

This function was added in MySQL version 4.1. It returns a string result
with the concatenated values from a group:
mysql> SELECT student_name,
    -> GROUP_CONCAT(test_score)
    -> FROM student
    -> GROUP BY student_name;

or:
mysql> SELECT student_name,
    -> GROUP_CONCAT(DISTINCT test_score
    -> ORDER BY test_score DESC SEPARATOR " ")
    -> FROM student
    -> GROUP BY student_name;

In MySQL you can get the concatenated values of expression combinations. You
can eliminate duplicate values by using DISTINCT. If you want to sort values
in the result you should use ORDER BY clause. To sort in reverse order, add
the DESC (descending) keyword to the name of the column you are sorting by
in the ORDER BY clause. The default is ascending order; this may be
specified explicitly using the ASC keyword. SEPARATOR is the string value
which should be inserted between values of result. The default is a comma
(`","'). You can remove the separator altogether by specifying SEPARATOR "".
You can set a maximum allowed length with the variable group_concat_max_len
in your configuration. The syntax to do this at runtime is:
SET [SESSION | GLOBAL] group_concat_max_len = unsigned_integer;

If a maximum length has been set, the result is truncated to this maximum
length. The GROUP_CONCAT() function is an enhanced implementation of the
basic LIST() function supported by Sybase SQL Anywhere. GROUP_CONCAT() is
backward compatible with the extremely limited functionality of LIST(), if
only one column and no other options are specified. LIST() does have a
default sorting order.
----------------------------------------------------------------------------
---------------------------------

So a bunch of open source nerds can do this but MS can't ?? :)

Interestingly, the *same* functionality with the same ease of use
has been in RAC using @concatenate or list() for quite a while!
(http://www.rac4sql.net/onlinehelp.asp?topic=236)

There's an interesting message in all this but I'll leave that to the
reader:)

RAC v2.2 and QALite @
www.rac4sql.net



Relevant Pages

  • Re: why use the sealed ?
    ... > I'll want to add functionality to something at a later date. ... > I sortof wish you could add functionality to (or replace members of) ... > exceeds past the end of the string. ... > application to be a Remoting Client. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Predicting the Future and Kolmogorov Complexity
    ... to the source string), k scales with the string, thus destroying the ... excess of symmetry or a lack of it that strikes you as particularly ... The same thing is true of radio signals. ... What do I mean by levels of functionality? ...
    (talk.origins)
  • Re: basic_string causes crash in _vsnprintf???
    ... and any other output string sets used. ... want or revert back to the old stl. ... >> this functionality so while it was not a standard STL implementation ... > In STLport it's just luck that it "works". ...
    (microsoft.public.vc.stl)
  • Re: Get/Set vs Public Variables
    ... string firstname; ... EVER will need any functionality in getters and setters for the two string ... databinding that it can bind only to properties and not to variables. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: return multiple rows from sql statement
    ... strings from input values is almost certainly a safe path to SQL ... Also, being a MySQL function, it knows what MySQL needs or uses. ... All characters that are entered in the fields make their way into the database unaltered. ... The insert of what surprisinlgly was NOT a syntax error, but a string called "mysql_insert_id" into an integer field resulted in the value zero being put in. ...
    (comp.lang.php)