Results 1 to 6 of 6

Thread: [RESOLVED] MS SQL - Group by

Hybrid View

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Resolved [RESOLVED] MS SQL - Group by

    Simple quick question.

    I`m using a simple group by and instead of getting the results I expect, MS Sql seems tso have merged the data, case insensitively.

    eg.
    RUA or Rua or rua all get put together as RUA (or whichever record it finds first).

    I don`t remember having this problem in Access. If the data was different I got different lines.

    Is it an easy fix? A setting on the MS Sql? an extra option in the SQL statement ?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: MS SQL - Group by

    Well, what's your query?
    What's a sample of the data in the table(s)?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: MS SQL - Group by

    You can try putting a CS (case sensitive) COLLATE on your query

    Code:
    COLLATE SQL_Latin1_General_CP1_CS_AS
    You'll have to experiment with placement - or maybe make a temp table and define that column as a CS collate...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: MS SQL - Group by

    SQL is like :
    Code:
    SELECT afield
      FROM atable
    GROUP BY afield
    in the field i have data like : RUA, Rua, R, Av, Avenida, AVENIDA
    the grouped result is : RUA, R, Av, AVENIDA

    Szlamany: I'll have a try, thanks for the tip. Is the default usually case insensitive?
    Last edited by Ecniv; Jul 18th, 2017 at 07:22 AM.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: MS SQL - Group by

    Quote Originally Posted by Ecniv View Post
    ...Szlamany: I'll have a try, thanks for the tip. Is the default usually case insensitive?
    The default is however your server was installed - it's a site installation setting.

    I've never seen a site that was installed as case-sensitive - that would be very interesting.

    The only reason I know about the collate is because I had a user that upgraded SQL and selected a different collation then the database and sprocs were created with. I had to add all kinds of COLLATE's to TEMP TABLE's that referred to VARCHAR() fields. What a nightmare that was...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: MS SQL - Group by

    Code:
    SELECT afield COLLATE SQL_Latin1_General_CP1_CS_AS tp
    FROM atable
    GROUP BY afield COLLATE SQL_Latin1_General_CP1_CS_AS
    ORDER BY tp
    The above works as I wanted/expected. Thanks Szlamany

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width