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 ««123»»

SELECT and WHERE without FROM Expand / Collapse
Author
Message
Posted Thursday, June 23, 2011 3:14 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 7:39 AM
Points: 9,370, Visits: 6,467
Nice question, thanks.



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

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1130241
Posted Thursday, June 23, 2011 3:17 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Saturday, May 18, 2013 1:44 AM
Points: 953, Visits: 1,875
You don't even need the WHERE clause. I've just done an SSIS step where I needed a single row returned, but didn't care about the contents, so I used

SELECT 1

and it worked fine.
Post #1130243
Posted Thursday, June 23, 2011 8:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, July 09, 2012 12:09 PM
Points: 6, Visits: 16
I'd have got it right had I not accidentally clicked Parse instead of Execute!
Post #1130445
Posted Thursday, June 23, 2011 8:07 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232, Visits: 1,046
Nice question. It makes me smile to see "where 1 = 1" or "while 1 = 1" in code.
Post #1130453
Posted Thursday, June 23, 2011 8:15 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, May 10, 2013 8:09 AM
Points: 254, Visits: 1,056
I'm enjoying the T-SQL questions this week!

Leonard
Madison, WI
Post #1130461
Posted Thursday, June 23, 2011 8:22 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232, Visits: 1,046
Andrew Watson-478275 (6/23/2011)
You don't even need the WHERE clause. I've just done an SSIS step where I needed a single row returned, but didn't care about the contents, so I used

SELECT 1

and it worked fine.

I think the concept the question was testing is;
"Do you need a From clause to use a where clause?"

I hope we all understand that a where clause is not needed for a SELECT statement.

i.e. SELECT @ParameterName = @@Version
SELECT @ParameterName

Post #1130467
Posted Thursday, June 23, 2011 9:00 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 9:31 AM
Points: 1,039, Visits: 1,356
Carlo Romagnano (6/23/2011)
If the condition of the WHERE clause validates to true then the result set is returned. If it does not, the result set is empty.

This is true only if you do not use COUNT(*):
select count(*)  cnt
where 1 =0

One row is returned despite the WHERE condition is false.


This is true of aggregate functions, not just COUNT(*) -- the where condition filters the input to the aggregate functions, not the output from them.

Try
select sum(5)
where 1 = 0

Post #1130510
Posted Thursday, June 23, 2011 9:13 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733, Visits: 12,332
straight up, fundamental question.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1130538
Posted Thursday, June 23, 2011 9:40 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Friday, May 10, 2013 11:54 AM
Points: 749, Visits: 3,767
Terrific question! Thanks.

______________________________________________________________________
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
Post #1130583
Posted Thursday, June 23, 2011 10:44 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:52 AM
Points: 2,574, Visits: 1,532
Nice question. I have used the "select '123' " or "select 5" syntax before but didn't think to ever try a where clause with it.
Post #1130652
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse