|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, April 17, 2013 10:57 PM
Points: 1,491,
Visits: 3,008
|
|
sknox (6/23/2011)
.... the where condition filters the input to the aggregate functions, not the output from them. ...
True. And of course this is because the Where clause filters input to the Select, regardless of it using an aggregate function. That's why one may not use an alias in the Where clause.
This code wouldn't work because MyData is not a real columnName in table MyVeryLongTableName.
Select tbl_a.RidiculouslyComplicatedColumnName as MyData from MyVeryLongTableName tbl_a join AnotherVeryLongTableName tbl_b on tbl_b.key = tbl_a.key where MyData = 'SearchString'
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Tuesday, April 09, 2013 1:20 PM
Points: 936,
Visits: 1,184
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, July 25, 2012 9:04 PM
Points: 542,
Visits: 187
|
|
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.
Good One didn't know that it will still return even if where condition is false. Not to forget that basic idea of question is select still does return result even if it's missing from clause. Keep it up... Cheers
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
I wonder which of the following (if either) is more efficient:
select @a = 1 where @b = 0 or
if @b = 0 set @a = 1
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
Toreador (6/24/2011)
I wonder which of the following (if either) is more efficient: select @a = 1 where @b = 0 or if @b = 0 set @a = 1 "if" runs better
declare @d datetime ,@a int ,@b int ,@i int
set @d = getdate() set @i = 0 while @i < 1000000 begin if @b = 0 set @a = 1 set @i = @i + 1 end
print datediff(millisecond,@d,getdate()) set @d = getdate() set @i = 0 while @i < 1000000 begin select @a = 1 where @b = 0 set @i = @i + 1 end
print datediff(millisecond,@d,getdate())
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
Toreador (6/24/2011)
I wonder which of the following (if either) is more efficient: select @a = 1 where @b = 0 or if @b = 0 set @a = 1 The best one seems to be "if" + "select" if @b = 0 (see last test):
declare @d datetime ,@a int ,@b int ,@i int
set @b = 0
set @d = getdate() set @i = 0 while @i < 1000000 begin if @b = 0 set @a = 1 set @i = @i + 1 end
print datediff(millisecond,@d,getdate()) set @d = getdate() set @i = 0 while @i < 1000000 begin select @a = 1 where @b = 0 set @i = @i + 1 end
print datediff(millisecond,@d,getdate())
set @d = getdate() set @i = 0 while @i < 1000000 begin if @b = 0 select @a = 1 set @i = @i + 1 end
print datediff(millisecond,@d,getdate())
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 6:46 AM
Points: 1,074,
Visits: 1,130
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 15, 2013 10:35 AM
Points: 594,
Visits: 654
|
|
I have used this before to test something... but I can't remember what it was!!! Except I used WHERE 1=0
My brain is all RAM and no HD... now where did that swapfile go to?...
Peter Trast Microsoft Certified ...(insert many literal strings here) Microsoft Design Architect with Alexander Open Systems
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Yesterday @ 1:06 PM
Points: 469,
Visits: 192
|
|
Good question that was straight forward to figure out.
Thanks.
|
|
|
|