This is a performance based question, not a "I don't understand" or "best practice" question.
I have a varchar field in a SQLServer database that is guaranteed to be longer than 7 chars. I need to extract a char(4) field consisting of the 2nd, 3rd, 4th and 5th chars in the varchar.
For example if the varchar had the value 1234567890 I would be looking for the 2345 part.
Is there a performance benefit to using a substring over a right-left combo?
SELECT SUBSTRING(account,2,4) FROM payment
or
SELECT RIGHT(LEFT(account,5),4) FROM payment
I have noticed a slight advantage by using a right-left on a table with 1,760,335 records, but I am not sure if this is due to caching queries or the like.
UPDATE I've done a bit more homework. It seems that in this case the Right-Left is ultimately performed as a Right-Substring. Is this a rule? or is it just the way SQLServer decided to skin this particular cat?