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.
Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers. Here are some hints to get started.
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.
There is a UNION ALL in the code sample. But only UNION in the query and plan screenshots.
i get a page not found error for https://voiceofthedba.com/2022/09/14/skipping-the-leading-digit-in-t-sql-sqlnewblogger/
which is the link in the “I wrote about before” sentence
Somehow I lost this post. Crazy.