Link to home
Start Free TrialLog in
Avatar of Stefan Motz
Stefan MotzFlag for United States of America

asked on

T-SQL: Is there a better way to write 'where column_name like '%CS?

Hi Experts,
I would like to do an update. What would be the best way to do it if mail_cd is always 5 characters and I'd like to capture the last two characters only? This is how I'm doing it now but I'm curious if there is a better way to do it:

update Employees set Department ='Customer Service' where mail_cd like '%CS'
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ste5an - Does that mean that LIKE '%CS' is not SARGable, but LIKE 'CS%' is?  
If so, good to know, learn something new every day..
Avatar of Stefan Motz

ASKER

Thank you all!
Thanks for the split.  Good luck with your code.  -Jim
@Jim: Yup, LIKE 'xyz%' can use an index seek.