There was an interesting question in a forum, which I wrote about before. How do you skip the leading digit in a numeric value. I had looked at a UNION, but someone had a better suggestion, so I’m adding to the post.
In the previous post, I used a <> and then a > and < with a UNION. Howver, someone noted that NOT BETWEEN is an option. I could rewrite the query this way:
SELECT * FROM dbo.Room AS r WHERE room NOT BETWEEN 200 AND 299
This gives me the same result:
This also results in a seek.
The BETWEEN or NOT BETWEN is sargable, meaning we can use an index to find those values that fall into this ordering and exclude them.
Worth remembering BETWEEN when writing queries for ranges.
SQL New Blogger
An update to my post, showing a better way, showing I am happy to take advice from others, and I can improve code. This is a skill that employers need, especially when teams need to become more consistent with coding when working together. Showing you can adapt and grow is a good skill.
You could write a simple blog like this that shows how you might change some code you wrote in the past. I bet it takes less than 30 minutes.