Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««1234»»»

ANY Expand / Collapse
Author
Message
Posted Friday, June 20, 2008 7:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 13,872, Visits: 9,596
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
Post #520664
Posted Friday, June 20, 2008 7:50 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, December 13, 2012 3:28 PM
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.
Post #520686
Posted Friday, June 20, 2008 9:00 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, September 18, 2014 7:50 PM
Points: 5,322, Visits: 25,235
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
Post #520795
Posted Friday, June 20, 2008 10:10 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 9, 2009 2:58 PM
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!!! :D

Yama Kamyar
Post #520868
Posted Friday, June 20, 2008 10:24 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 9:56 AM
Points: 31,035, Visits: 15,461
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
Post #520877
Posted Friday, June 20, 2008 10:24 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:51 AM
Points: 2,716, Visits: 2,459
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!!]
Post #520878
Posted Friday, June 20, 2008 10:30 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Saturday, January 25, 2014 2:45 PM
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?)
Post #520880
Posted Friday, June 20, 2008 10:36 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 9:56 AM
Points: 31,035, Visits: 15,461
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
Post #520881
Posted Friday, June 20, 2008 12:25 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, September 18, 2014 11:32 AM
Points: 2,669, Visits: 779
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
Post #520966
Posted Friday, June 20, 2008 12:33 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 9:56 AM
Points: 31,035, Visits: 15,461
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
Post #520973
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse