Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


FILTER


FILTER

Author
Message
Lokesh Vij
Lokesh Vij
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1788 Visits: 1599
Comments posted to this topic are about the item FILTER

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter


demonfox
demonfox
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1355 Visits: 1192
my query unexpectedly took 15 minutes to run and I cancelled it after that ..
then I came to ssc and an easy one to start the tuesday ...

felt relieved ...time to stress on another pawn ..

thanks for the question..

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19487 Visits: 13250
Easy one, thanks.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Raghavendra Mudugal
Raghavendra Mudugal
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1792 Visits: 2958
Thanks for the question Lokesh-ji, (so simple and yet so much to consider).

(actually i did not focus on the collation but saw the count(*) and then I chose 6 Hehe , not a right way but got by 1 point ;-) )

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Lokesh Vij
Lokesh Vij
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1788 Visits: 1599
Raghavendra Mudugal (9/17/2012)
Thanks for the question Lokesh-ji, (so simple and yet so much to consider). )


Glad to know that Raghu..sometimes we are so engrossed in the perplexities of complex issues that we forget the basics ;-) It was just a small effort to make you all revise:-)

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter


Raghavendra Mudugal
Raghavendra Mudugal
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1792 Visits: 2958
Sorry for taking this thread out of the scope... (this is nothing to do with the QToD's objective, but was playing around and kind of stuck with this...Whistling )

Considering the same data given, can anyone advise what is happening on #3 ?

It is giving me this result...

COL2 (No column name)
AB 2
xy 1



But I was expecting

COL2 (No column name)
AB 2
aB 1
xy 1




-- #1
SELECT COL2, COUNT(COL2)
FROM test
WHERE col2 IN ( 'AB', 'aB', 'xy' )
GROUP BY COL2

-- #2
SELECT COL2, COUNT(COL2 COLLATE SQL_Latin1_General_CP1_CS_AS)
FROM test
WHERE col2 IN ( 'AB', 'aB', 'xy' )
GROUP BY COL2

-- #3
SELECT COL2, COUNT(COL2)
FROM test
WHERE col2 COLLATE SQL_Latin1_General_CP1_CS_AS IN ( 'AB', 'aB', 'xy' )
GROUP BY COL2

-- #4
SELECT COL2, COUNT(COL2 COLLATE SQL_Latin1_General_CP1_CS_AS)
FROM test
WHERE col2 COLLATE SQL_Latin1_General_CP1_CS_AS IN ( 'AB', 'aB', 'xy' )
GROUP BY COL2



ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
philip.cullingworth
philip.cullingworth
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1494 Visits: 969
Raghu,

The results you are getting are due to you only specifying the collation on the where clause.

The query is selecting rows 1, 3 and 6 since they are the rows that match when the case sensitive collation is specified.

However the Group By clause does not specifiy Case Sensitive and so the results are grouped case insensitive, combining the AB and aB.

You would need the code below to get your expected result (assuming the count next to AB was meant to be 1)

SELECT COL2 COLLATE SQL_Latin1_General_CP1_CS_AS, COUNT(COL2)
FROM testQOTD
WHERE col2 COLLATE SQL_Latin1_General_CP1_CS_AS IN ( 'AB', 'aB', 'xy' )
GROUP BY COL2 COLLATE SQL_Latin1_General_CP1_CS_AS


demonfox
demonfox
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1355 Visits: 1192
I think it should work ...

SELECT COL2 COLLATE SQL_Latin1_General_CP1_CS_AS, COUNT(COL2 COLLATE SQL_Latin1_General_CP1_CS_AS)
FROM #test
WHERE col2 IN ( 'AB', 'aB', 'xy' )
GROUP BY COL2 COLLATE SQL_Latin1_General_CP1_CS_AS



~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
demonfox
demonfox
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1355 Visits: 1192
philip.cullingworth (9/18/2012)
Raghu,

The results you are getting are due to you only specifying the collation on the where clause.

The query is selecting rows 1, 3 and 6 since they are the rows that match when the case sensitive collation is specified.

However the Group By clause does not specifiy Case Sensitive and so the results are grouped case insensitive, combining the AB and aB.

You would need the code below to get your expected result (assuming the count next to AB was meant to be 1)

SELECT COL2 COLLATE SQL_Latin1_General_CP1_CS_AS, COUNT(COL2)
FROM testQOTD
WHERE col2 COLLATE SQL_Latin1_General_CP1_CS_AS IN ( 'AB', 'aB', 'xy' )
GROUP BY COL2 COLLATE SQL_Latin1_General_CP1_CS_AS



that is what I meant , and yes there is no need to add collation in the count ....

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
skanker
skanker
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1059 Visits: 1385
Nice question to start the day. Thanks. :-D
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search