Wednesday, March 21, 2012

Rewrite to Sargable

Is there a way to rewrite either of the following where clause items to allow
them to be SARGABLE?
1. ISDATE(Team.TextValue) = 1 -- Ensure that the value in the TextValue
field is a date. TextValue datatype is varchar(25).
2. LEFT(Team.Codes, 1) <> '-' -- Exclude the Codes that begin with a '-'.
Codes datatype is varchar(10).
Message posted via http://www.droptable.com
For #2, try:
Team.Codes not like '-%'
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:6a089625d4de6@.uwe...
Is there a way to rewrite either of the following where clause items to
allow
them to be SARGABLE?
1. ISDATE(Team.TextValue) = 1 -- Ensure that the value in the TextValue
field is a date. TextValue datatype is varchar(25).
2. LEFT(Team.Codes, 1) <> '-' -- Exclude the Codes that begin with a '-'.
Codes datatype is varchar(10).
Message posted via http://www.droptable.com
|||Hi
For #1
If Team.TextValue should only be dates, you may want to validate it on the
UI. If it can be dates and other entries you may want to hold a datetype flag
instead.
John
"cbrichards via droptable.com" wrote:

> Is there a way to rewrite either of the following where clause items to allow
> them to be SARGABLE?
> 1. ISDATE(Team.TextValue) = 1 -- Ensure that the value in the TextValue
> field is a date. TextValue datatype is varchar(25).
> 2. LEFT(Team.Codes, 1) <> '-' -- Exclude the Codes that begin with a '-'.
> Codes datatype is varchar(10).
> --
> Message posted via http://www.droptable.com
>

No comments:

Post a Comment