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


ANY


Author
Message
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14369 Visits: 9729
Very cool. I wasn't aware of the Any/Some/All operators in SQL. Didn't even know they existed. Learned something from this one.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
WarePhreak
WarePhreak
SSC Veteran
SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)

Group: General Forum Members
Points: 257 Visits: 50
I found the reason given lacking as well and was thinking along the lines of the other comments regarding case.

Did learn about the ANY clause though.
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5689 Visits: 25280
Steve thanks for an eye opening question. Never knew nor would I ever find out about the "some / any" operators.

Now answer the following question:

How many hours have you spent memorizing BOL and MSDN pages for T-SQL in revision 2005?

(Worth hundreds of points)

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Yama Kamyar
Yama Kamyar
SSC-Enthusiastic
SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)SSC-Enthusiastic (100 reputation)

Group: General Forum Members
Points: 100 Visits: 9

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Table_1]') AND type in (N'U'))
DROP TABLE [dbo].[Table_1]

/****** Object: Table [dbo].[Table_1] Script Date: 06/20/2008 08:46:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Table_1](
[column1] [nchar](10) NULL,
[column2] [nchar](10) NULL,
[column3] [nchar](10) NULL,
[column4] [nchar](10) NULL
) ON [PRIMARY]


INSERT [Table_1]
([column1], [column2], [column3], [column4])
VALUES
('Value1', 'Value2', 'Value3', 'Value4')


IF 'Value1' < ANY ( SELECT [column1] FROM [Table_1] )
SELECT '1' TEST1
ELSE
SELECT '0' TEST1;

IF 'Value4' < ANY ( SELECT [column1] FROM [Table_1] )
SELECT '1' TEST2
ELSE
SELECT '0' TEST2;

IF 'Value4' = ANY ( SELECT [column1] FROM [Table_1] )
SELECT '1' TEST3
ELSE
SELECT '0' TEST3;

IF 'Value1' = ANY ( SELECT [column1] FROM [Table_1] )
SELECT '1' TEST4
ELSE
SELECT '0' TEST4;



ONly Test4 returns TRUE!
Please refund us our 2 points!!! BigGrin

Yama Kamyar
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36008 Visits: 18728
The query shows "value1", not "Value1", which definitely depends on case sensitivity.

however, in any case, "value1" is less than "value2" and the others. Your example bends the rows into columns. This is what the question asked:

/****** Object: Table [dbo].[Table_1] Script Date: 06/20/2008 08:46:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Table_1](
[column1] [nchar](10) NULL
) ON [PRIMARY]

INSERT [Table_1] ([column1]) VALUES ('Value1')
INSERT [Table_1] ([column1]) VALUES ('Value2')
INSERT [Table_1] ([column1]) VALUES ('Value3')
INSERT [Table_1] ([column1]) VALUES ('Value4')

select * from Table_1
IF 'Value1' < ANY ( SELECT [column1] FROM [Table_1] )
SELECT '1' TEST1
ELSE
SELECT '0' TEST1;

Drop TABLE [dbo].[Table_1]



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
kevriley
kevriley
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2751 Visits: 2606
Yama,

you have changed the question!!

It's not a table with 4 columns, it's a table with one column 'column1' with 4 values 'value1','value2','value3','value4'



Kev

[whoops - beaten to it by Steve!!]
Pat Reiter
Pat Reiter
Valued Member
Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)Valued Member (62 reputation)

Group: General Forum Members
Points: 62 Visits: 125
Drat! I thought that it was a case-sensitivity trick question, but couldn't remember which case sorts to the top. (And it's cheating to research anything for the QOD, right?)
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36008 Visits: 18728
Upper case before lower case (http://www.asciitable.com/), remember that we only had upper case way back when.

But do the QOD however you want. Some people want the points, maybe it's a resume bullet, so they'll research or run test code. Some guess to see if they know or if they can make an educated guess.

All's fair in how you do it. It should mean something to you if you participate, whatever that is (learning tool, quiz, indicative of knowledge, etc.).

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
Jamie-2229
Jamie-2229
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2955 Visits: 831
I have a different result:

--Assuming that I have the following values in the TimeGroup table (value1, value2, value3, value4), what does this query return?
CREATE TABLE #TimeGroup(column1 VARCHAR(50),column2 VARCHAR(50),column3 VARCHAR(50),column4 VARCHAR(50))
INSERT INTO #TimeGroup(column1, column2,column3, column4) VALUES('value1','value2','value3','value4')

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

DROP TABLE #TimeGroup

Jamie
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36008 Visits: 18728
The values are in rows, not columns.

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
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