Author: way0utwest

  • Using a Regular Expression to Detect a Number–#SQLNewBlogger

    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.

    I had a customer recently that was looking to work with Data Masker for SQL Server and had questions about how to handle some situations. In this case, they needed to detect a number type in a field that was overloaded with multiple types of data. Here’s an example of what they had in their “string” (varchar) field. Look at the stringvalue column below:

    2022-06-07 08_23_13-SQLQuery1.sql - ARISTOTLE.SimpleTalk (ARISTOTLE_Steve (58))_ - Microsoft SQL Ser

    If the string was a “nnn nnn nnnn” number value, then they wanted to change it. If it had other values, then leave it alone. This is really a query problem and a WHERE clause to structure.

    One would think this is where you use ISNUMERIC() and try that. If I run this, I get zero rows back.

    SELECT d.stringvalue
    FROM dbo.ddmdemo AS d
    WHERE ISNUMERIC(d.stringvalue) = 1

    This isn’t really a number, as the sequence has spaces. What if we try this:

    SELECT d.stringvalue
    FROM dbo.ddmdemo AS d
    WHERE ISNUMERIC(REPLACE(' ', '', d.stringvalue)) = 1

    It also returns no values.

    Really, this appears to really be a regular expression type of query, so I could do this, using LIKE.

    SELECT *
    FROM dbo.ddmdemo AS d
    WHERE d.stringvalue LIKE '[0-9]%'

    That, however, gives me two rows in this set of data. I see these results:

    2022-06-07 08_31_14-SQLQuery1.sql - ARISTOTLE.SimpleTalk (ARISTOTLE_Steve (58))_ - Microsoft SQL Ser

    The reason is that I am matching the first character only. The argument is a pattern and using square brackets implies a single character in a range. Since there are a lot of different patterns, and the “234223 Test” matches that, I ought to be more specific.

    This particular pattern from the customer is 3 numbers, space, 3 numbers, space, 4 numbers. Anything else is non matching. Since there could be trailing spaces, I’d really want this:

    SELECT d.stringvalue
    FROM dbo.ddmdemo AS d
    WHERE d.stringvalue LIKE '[0-9][0-9][0-9] [0-9][0-9][0-9] [0-9][0-9][0-9][0-9]'

    This returns my single row. It would match any row that is of the pattern “nnn nnn nnnn” where n is a numerical value from 0-9.

    There are other considerations here, and certainly this is likely to be a complex set of masking rules, but this shows a relatively simple way to detect a numerical pattern in a string.

    SQL New Blogger

    This was an interesting case. I initially thought  LIKE and an expression, but thought maybe there was a quicker way with isnumeric(). I didn’t find one, so I explained that and then the way that did work for me.

    To me, this gives someone who glances at my blog a bit of insight into how I think and what I considered. This might be how they think, or someone on their team thinks. This might get me an interview.

    Write about the problems you solve and how/why you do it.

  • Becoming a Better DBA

    One of the things that I try to advocate for is that more of you actively manage your careers and find ways to improve your skills. I want you to be more impressive and find an amazing job for you. Not my job, because I have the best job in the world, but I hope you find a job that you love as much as I love mine.

    It does take effort, work, and focus. It’s something else to manage in life. I certainly don’t want you to only care about work. After all, we work to live, not live to work.

    That being said, I think you can build the habit of regular career improvement. For those of you that work as DBAs, I found this list of things that help improve your productivity. The first few items are practical having a routine of things to check and a way to monitor your systems. Those are core skills and a base from which to build. I might stress backups, restores and DR as well, since the main thing is that you can protect and recover data if everything else falls apart.

    However, the last few items are less tangible. How do you keep up, explore, and try things? In what area or topic should you start? What’s important? I find many people struggle with these less directed pieces of advice. If I want to keep up, what do I do? If I want to experiment or ask about something, what is the most efficient way to do this?

    There’s advice in the article, but here’s my main thought. Don’t try to be efficient or perfect. Just pick the thing that’s in front of you. Pick something that someone asked you about and you didn’t know. Or maybe the thing that looked interesting? Just move forward.

    Most of the work we do to improve ourselves isn’t tightly focused at first. It’s just a step forward and it’s not a permanent step. If you decide to start learning about something such as Availability Groups and then realize you don’t like this area or it isn’t important, just switch to something else. Your time isn’t wasted because even if you don’t use that skill, you learned about learning something. And you learned something about yourself and what you enjoy. Move on and try something else.

    For me, I started SQL Server Central. but I liked newsletters similar to the one I send out each week because they gave me something to learn about. I used to troll forums at various places and see the “active threads“. I’d try to answer random questions, even if I didn’t post the answers. I started to blog and write, mostly to see if I could explain things back in a way that made sense. It became a career, but before that it was a way to impress hiring managers. It also forced me to learn more about little topics and all of that knowledge helped me to be more effective at my job.

    Taking a little time every week to learn something, work on your career, and document it (hopefully as a #SQLNewBlogger). It is a good way to improve your skills and also showcase them for the next person that hires (or promotes) you. Hopefully into a position that you desire and choose.

    Steve Jones

    Listen to the podcast at Libsyn, Stitcher, Spotify, or iTunes.

  • Daily Coping 15 Jun 2022

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

    Today’s tip is to think of what is a little thing you are grateful for today?

    I’m grateful that I enjoy my job. There are lots of things to be grateful for in my life, but this is one that occurred to me. My job can be tough some times, especially now with a lot of travel, and it can stink sometimes when deadlines or responsibilities create stress.

    However, overall, I enjoy my job. I like the people, the challenges, the discussions, and the travel. That’s a nice perk that I can earn a good living and enjoy the process of doing so.

  • Daily Coping 14 Jun 2022

    I started to add a daily coping tip to the SQLServerCentral newsletter and to the Community Circle, which is helping me deal with the issues in the world. I’m adding my responses for each day here. All my coping tips are under this tag.

    Today’s tip is to list what values are important? Use them today.

    Compassion, Positivity, Perseverance.

    For me, these matter. This past weekend I was camping with family and friends. Friends can be hard, and I had some in my family that were struggling with the extra people. I made it a point to listen and not offer solutions or judgment, but be understanding and supportive. And give a hug.

    I’ve also been working to rehab my ankle. I couldn’t do a lot of walking, though I did some. Still using a cane, but also trying to remain positive that it is getting better.

    I also had to persevere and keep moving along, even when the ankle hurts and I’m a little sad I can’t participate as much as everyone else. However, I keep moving forward.