|
-
Jul 16th, 2017, 09:44 AM
#1
Thread Starter
Don't Panic!
[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 ?
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...
-
Jul 16th, 2017, 11:17 AM
#2
Re: MS SQL - Group by
Well, what's your query?
What's a sample of the data in the table(s)?
-
Jul 16th, 2017, 11:57 AM
#3
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...
-
Jul 18th, 2017, 07:14 AM
#4
Thread Starter
Don't Panic!
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.
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...
-
Jul 18th, 2017, 07:21 AM
#5
Thread Starter
Don't Panic!
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
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...
-
Jul 18th, 2017, 11:23 AM
#6
Re: MS SQL - Group by
 Originally Posted by Ecniv
...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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|