Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to avoid subs() on left side of equal
Message
 
 
À
16/11/2009 11:08:07
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01434947
Message ID:
01434952
Vues:
61
This message has been marked as a message which has helped to the initial question of the thread.
>>Performance wise I know we should avoid having scalar functions on the left side of the equal in the where clause. Anybody have an idea on how to avoid it in something like below?
>>
>>Thanks
>>
>>
>>Select min(sdatetime) as FirstDate 
>>from dbo.Meetings (nolock) 
>>where iscancelled=0
>>and roomclosed=0
>>and isblock=0
>>and substring(scheduledBy,1,4)<>'TEST'
>>and substring(scheduledBy,1,3)<>'CQI'
>>
>
>
>There may be other ways
>
>
>>Select min(sdatetime) as FirstDate 
>>from dbo.Meetings (nolock) 
>>where iscancelled=0
>>and roomclosed=0
>>and isblock=0
>and scheduledBy not like 'TEST%'  
>and scheduledBy not like 'CQI%'
>
The other way would be a left join with itself and a like condition, e.g.
;with cte_ToExclude as (select IDField 
from dbo.Meetings (nolock) 
where iscancelled=0
and roomclosed=0
and isblock=0
and (scheduledBy like 'TEST%'  
OR scheduledBy like 'CQI%'))

select min(M.sDateTime) as FirstDate 
from dbo.Meetings (nolock) M
where M.iscancelled=0
and M.roomclosed=0
and M.isblock=0 LEFT JOIN cte_ToExclude C on M.IdField = C.IDField where c.IDField IS NULL
Or use not exist condition here:
select min(M.sDateTime) as FirstDatefrom dbo.Meetings (nolock) M
where M.iscancelled=0
and M.roomclosed=0
and not exists(select 1 from 
from dbo.Meetings (nolock)  M2
where M2.iscancelled=0
and M2.roomclosed=0
and M2.isblock=0
and M2.scheduledBy like 'TEST%'  and M2.IdField = M1.IDField) and not exists (select 1 from 
from dbo.Meetings (nolock)  M3
where M3.iscancelled=0
and M3.roomclosed=0
and M3.isblock=0
and M3.scheduledBy like 'CQl%'  and M3.IdField = M1.IDField)
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform