jarid.lawson (10/8/2012) ScottPletcher (10/8/2012)
lastname LIKE '%[/]%' AND
lastname NOT LIKE '%[/]%[/]%'
Still have to add the line that removes / in the first character. I also believe you would want to remove any where / was the last character...
And Left(Ltrim(LastName), 1) <> '/'
And Right(Rtrim(LastName),1) <> '/'
I'm curious if this would not be a good option from an execution plan perspective? Are there better / faster ways of completing this?
Oops, I didn't initially read down far enough to see the new requirement of not a leading /:
lastname LIKE '[^/]%[/]%' AND
lastname NOT LIKE '[^/]%[/]%[/]%'
In theory this could potentially be faster with a covering index on lastname (probably likely, if you plan on running this query very often), whereas the queries using REPLACE(...) or any other function on the lastname column would require a full table scan.
That is, "lastname [NOT] like" is SARGable but "<function>(... lastname ...)" is not.
SQL DBA,SQL Server MVP('07, '08, '09)Prosecutor James Blackburn, in closing argument in the "Fatal Vision" murders trial: "If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them."