|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
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
|
|
|
|
|
SSC 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.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 9:21 AM
Points: 5,099,
Visits: 20,191
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 09, 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
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Yesterday @ 1:47 PM
Points: 31,406,
Visits: 13,722
|
|
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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 12:01 PM
Points: 2,677,
Visits: 2,273
|
|
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!!]
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, August 17, 2012 6:07 PM
Points: 62,
Visits: 124
|
|
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?)
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Yesterday @ 1:47 PM
Points: 31,406,
Visits: 13,722
|
|
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
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 6:57 PM
Points: 2,440,
Visits: 712
|
|
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
|
|
|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Yesterday @ 1:47 PM
Points: 31,406,
Visits: 13,722
|
|
|
|
|