Sorting - character after 'Z'?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Duy  Lam

    Sorting - character after 'Z'?

    I'm using collation SQL_Latin1_Gene ral_CP1_CI_AS and I need to sort a
    varchar field. There are some elements, however, that I want to come
    AFTER any alphabetic characters. Is there any character that sorts
    after "Z"? In normal ASCII, there are various characters that would
    sort after "Z" (e.g. "~"), but I can't seem to figure out what the case
    would be in the SQL_Latin1_Gene ral_CP1_CI_AS collation. Any ideas?

    thanks,
    Duy Lam

  • Simon Hayes

    #2
    Re: Sorting - character after 'Z'?


    "Duy Lam" <duylam@gmail.c om> wrote in message
    news:1119462033 .433216.3880@f1 4g2000cwb.googl egroups.com...[color=blue]
    > I'm using collation SQL_Latin1_Gene ral_CP1_CI_AS and I need to sort a
    > varchar field. There are some elements, however, that I want to come
    > AFTER any alphabetic characters. Is there any character that sorts
    > after "Z"? In normal ASCII, there are various characters that would
    > sort after "Z" (e.g. "~"), but I can't seem to figure out what the case
    > would be in the SQL_Latin1_Gene ral_CP1_CI_AS collation. Any ideas?
    >
    > thanks,
    > Duy Lam
    >[/color]

    Perhaps you can post a specific script to show what you want? Many
    characters might sort after 'Z', as you said - maybe you should check out
    ASCII(), CHAR(), UNICODE(), COLLATE and "Using Unicode Data" in Books
    Online? If you can post something that others can copy and paste into Query
    Analyzer, then there's a better chance that you'll get a useful answer.



    Simon


    Comment

    • Duy  Lam

      #3
      Re: Sorting - character after 'Z'?

      Well, it's not so much there's a specific script I have that I need to
      get working. I just want a way to enforce a certain order among rows.
      For instance, let's say I have a table

      T(someindex int, sortkey varchar(5), val int)

      ....and it's loaded with some data. for each row, the "sortkey" is a
      field so that a user (who's using my app) can manually enforce an order
      among "val"s. Normally it will be filled with some kind of alphanumeric
      data.

      I want to return the "val" column, but ordered by "sortkey". This, of
      course, is easily obtained by running:

      SELECT val FROM T ORDER BY sortkey

      but for some rows, I may want to force certain "val"s to appear at the
      end. One way, of course, is to set sortkey to "ZZZZZ" for those vals,
      but there might be a chance that "ZZZZZ" is an actual value set by the
      user. Thus I want some kind of character that is sorted even lower than
      "Z" to guarantee that it comes after any possible alphanumeric entry
      for "sortkey".

      as i mentioned, in ASCII there are a number of characters that follow
      'z', but I don't know any for the standard SQL_Latin1_Gene ral_CP1_CI_AS
      collation.

      Comment

      • Erland Sommarskog

        #4
        Re: Sorting - character after 'Z'?

        [posted and mailed, please reply in news]

        Duy Lam (duylam@gmail.c om) writes:[color=blue]
        > I'm using collation SQL_Latin1_Gene ral_CP1_CI_AS and I need to sort a
        > varchar field. There are some elements, however, that I want to come
        > AFTER any alphabetic characters. Is there any character that sorts
        > after "Z"? In normal ASCII, there are various characters that would
        > sort after "Z" (e.g. "~"), but I can't seem to figure out what the case
        > would be in the SQL_Latin1_Gene ral_CP1_CI_AS collation. Any ideas?[/color]

        Looks like you have to learn Icelandic. :-) The script below helps you
        out:

        CREATE TABLE slafs (a int IDENTITY,
        b AS char(a),
        c int NOT NULL)
        go
        INSERT slafs (c) SELECT TOP 255 OrderID FROM Northwind..Orde rs
        go
        SELECT * FROM slafs ORDER BY b
        SELECT * FROM slafs ORDER BY b COLLATE SQL_Latin1_Gene ral_CP1_CI_AS
        go
        DROP TABLE slafs


        --
        Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

        Books Online for SQL Server SP3 at

        Comment

        Working...