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


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:02 AM
Points: 13,637, Visits: 10,523
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
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 3:53 AM
Points: 1,223, Visits: 2,211
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, February 24, 2014 7:39 AM
Points: 9, Visits: 26
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, August 29, 2014 8:53 AM
Points: 271, Visits: 1,313
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 @ 5:11 AM
Points: 1,316, Visits: 1,687
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


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Friday, August 29, 2014 1:51 PM
Points: 21,644, Visits: 15,317
straight up, fundamental question.



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


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: Monday, July 14, 2014 10:08 AM
Points: 754, Visits: 3,816
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


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, August 29, 2014 10:23 AM
Points: 3,299, Visits: 1,978
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