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


ANY


Author
Message
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: Administrators
Points: 35981 Visits: 18727
Comments posted to this topic are about the item ANY

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
PrabodhM
PrabodhM
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1252 Visits: 63
I wonder if this one was to makeup the previous QotDLaugh
Danasegarane.A
Danasegarane.A
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 562
I am not able to understand this one

I run this query

if 'BLONP' < Any (select customerid from customers)
select '1'
else
select '0'

But it returns 1 only ?
liam.stirling
liam.stirling
SSC-Addicted
SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)SSC-Addicted (469 reputation)

Group: General Forum Members
Points: 469 Visits: 124
Danasegarane.A (6/19/2008)
I am not able to understand this one

I run this query

if 'BLONP' < Any (select customerid from customers)
select '1'
else
select '0'

But it returns 1 only ?


What's your customer table - I assume that the customerid column is some kind of char-based column for the above not to return you a conversion failure.

Try the following...

CREATE TABLE [dbo].[TimeGroup](
   [column1] [nchar](10) COLLATE Latin1_General_CI_AS NULL
) ON [PRIMARY]

Insert into the TimeGroup table values Value1, Value2, Value3, Value4

run the query as posted in the question and it will return 1 for any value in the if statement less than 'Value4'. Value4 is the highest value in you've added to column1, so here it will return 0. If you change the operator to =, it will return 1 for Value4.

i.e.
if 'Value1' < any ( select column1 from TimeGROUP )
   select '1'
else
   select '0'
Returns 1

if 'Value4' < any ( select column1 from TimeGROUP )
   select '1'
else
   select '0'

Returns 0

if 'Value4' = any ( select column1 from TimeGROUP )
   select '1'
else
   select '0'

Returns 1

and so on...Smile
Danasegarane.A
Danasegarane.A
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 562
No it is clear...


Thanks for the clarification Smile
majorbloodnock
majorbloodnock
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: 1113 Visits: 3062
Of course, strictly speaking the question will only be correct for case insensitive collations, since the values in the question are "value1, value2, value3 and value4", yet the comparison value is "Value1".

Nonetheless, a good question.

Semper in excretia, sumus solum profundum variat
Hugo Kornelis
Hugo Kornelis
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8307 Visits: 11538
majorbloodnock (6/20/2008)
Of course, strictly speaking the question will only be correct for case insensitive collations, since the values in the question are "value1, value2, value3 and value4", yet the comparison value is "Value1".

Nonetheless, a good question.


Strictly speaking, it's correct for case sensitive collations as well, since uppercase character sort before lowercase characters. (And in binary collations, ALL uppercase characters sort before ANY lowercase character). It would have been different if the table values were uppercase and the value in the query was lowercase.

However, even more strictly speaking, the result would have been an error if the database collation is case sensitive. After all, in a case sensitive collation, the tables TimeGroup and TimeGROUP are distinct BigGrin

But I do agree with your final statement - a good question to test understanding of a very little known SQL operator. Thanks, Steve! Wink


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
majorbloodnock
majorbloodnock
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: 1113 Visits: 3062
Hugo Kornelis (6/20/2008)
majorbloodnock (6/20/2008)
Of course, strictly speaking the question will only be correct for case insensitive collations, since the values in the question are "value1, value2, value3 and value4", yet the comparison value is "Value1".

Nonetheless, a good question.


Strictly speaking, it's correct for case sensitive collations as well, since uppercase character sort before lowercase characters. (And in binary collations, ALL uppercase characters sort before ANY lowercase character). It would have been different if the table values were uppercase and the value in the query was lowercase.

However, even more strictly speaking, the result would have been an error if the database collation is case sensitive. After all, in a case sensitive collation, the tables TimeGroup and TimeGROUP are distinct BigGrin

But I do agree with your final statement - a good question to test understanding of a very little known SQL operator. Thanks, Steve! Wink


Oops. My mistake. Thanks, Hugo.

Semper in excretia, sumus solum profundum variat
Anipaul
Anipaul
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6275 Visits: 1407
Excellent questions ..............Smile



StarNamer
StarNamer
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1294 Visits: 1992
I think the explanation of the answer is wrong. It says
If any value meets these criteria, then TRUE is returned to the IF statement and it is true in this case since "VALUE1" was given in the question.
In fact, I beleive it returns true because the values "VALUE2", "VALUE3" and "VALUE4" were given in the question!
The test
if 'Value1' < any (select 'Value1')
select 1
else
select 0

returns '0'. The code in the question returns '1' because
if 'Value1' < any (select 'value2' 
union all select 'value3'
union all select 'value4')
select 1
else
select 0

returns '1'.BigGrin

Derek
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