|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 7:39 AM
Points: 9,370,
Visits: 6,467
|
|
|
|
|
|
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.
|
|
|
|
|
Forum 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!
|
|
|
|
|
Ten 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.
|
|
|
|
|
SSC 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
|
|
|
|
|
Ten 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
|
|
|
|
|
Ten 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
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
Right 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
|
|
|
|
|
SSCrazy
      
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.
|
|
|
|