March 27, 2013 at 6:37 am
Hi All,
I'm working on database where a table contains an ID that is prefixed with a 2 letter identifier type
i.e
AB123456
AB345234
AB423423
XY456789
XY234344
Ideally i would like to remove the prefix completely and create a new column for this.
However I don't have the capacity to do this now as a lot of changes would be required.
My Question is, when querying the data, say i wanted to only get all XY records, would it be quicker if I created a new column storing these types. (AB,XY) and then filter where column = 'XY' while retaining the prefix on the id. Or create a bit column where XY is set to 1 and filter on this?
Or since the data is already setup with the prefix is it quicker just to filter where left 2 is XY?
Many thanks
March 27, 2013 at 6:42 am
WHERE IDColumn LIKE 'XY%'
Not LEFT, being a function on the column it would be non-SARGable. Like with a trailing wildcard can use indexes.
Edit: LEFT, not like in the previous sentence.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 27, 2013 at 7:10 am
GilaMonster (3/27/2013)
WHERE IDColumn LIKE 'XY%'Not like, being a function on the column it would be non-SARGable. Like with a trailing wildcard can use indexes.
Thanks Gila, had to look up sargable vs non-sargable, as usual SQL Server Cental is a fountain of knowledge
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy