I'm more of an Oracle bod, so wouldn't be sure about sql server, but stick
it through the sql analyzer tool to find out !
I've noticed in Oracle , if you do "where column=column" e.g. where
employee_name=employee_name, this has a (good) performance effect, as it
gives the optimizer the chance to use an index if it exists. I think it's an
undocumented feature though, so in sql server, while I doubt that 1=1 would
affect performance in anyway, employee_name=employee_name might affect it
(in a good way). It might be worth experimenting with it.
----- Original Message -----
From: "Tom Shearer "
<mssqldba-ezmlmshield-x74442049.[Email address protected]
To: "LazyDBA Discussion" <[Email address protected]
Sent: Wednesday, June 29, 2005 11:16 AM
Subject: Re: 1=1 ?
> does this have any effect on performance? I've always wondered this ;)
>
> ENEE1001 wrote:
>> I do this sometimes, but don't tell anyone.
>>
>> It's mainly seen where you're automatically generating the SQL from
>> another
>> program. If you add where 1=1, then you don't have to worry about the
>> "AND"
>> keyword, everything you add after that can just have the word "AND"
>> before
>> it. e.g. if you're giving the user the option to narrow things down in a
>> search engine you've written. It's a little bit lazy programming, but
>> very
>> convenient.
>>
>>
>> ----- Original Message -----
>> From: "ian" <mssqldba-ezmlmshield-x85823921.[Email address protected]
>> To: "LazyDBA Discussion" <[Email address protected]
>> Sent: Wednesday, June 29, 2005 9:36 AM
>> Subject: 1=1 ?
>>
>>
>>
>>>Hello all
>>>
>>>
>>>
>>>Can someone shed some light on reasons to use 1=1 in SQL clauses like
>>>the following :
>>>
>>>
>>>
>>>select *
>>>
>>>from sg..mytable with(nolock)
>>>
>>>where 1=1
>>>
>>>and (1=2 or f1 like 'JK%')
>>>
>>>and (1=2 or f2 in ('somevalue'))
>>>
>>>
>>>
>>>Thanks
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
>>>Website : http://www.LazyDBA.com
>>>To unsubscribe: http://www.lazydba.com/unsubscribe.html
>>>
>>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
>> Website : http://www.LazyDBA.com
>> To unsubscribe: http://www.lazydba.com/unsubscribe.html
>>
>>
>
>
>
> ---------------------------------------------------------------------
> TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
> Website : http://www.LazyDBA.com
> To unsubscribe: http://www.lazydba.com/unsubscribe.html
>
>
MS Sql Server LazyDBA home page