Daily Coping 21 May 2021

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 watch the sunset and reflect on the world.

I was hoping for a weekend off, but it’s not coming. Mother’s Day was slightly off, but we had my son’s college graduation party and one practice, so it was only a slight break. Since May, I’ve had volleyball on two weekends (and next) and this weekend I’m helping a kid move with some practices around that. I truly am looking forward to the season ending and a little more free time.

I write this because Thursday night was really the only time off this week. I scheduled yoga one night and had to cook, dinner with a friend another, and practice two others. As my wife went to feed horses, I sat outside watching and watching the sun start to go down.

I also grabbed a bottle of wine and a couple glasses to take out and just relax, sitting and thinking about the rapidly changing world, the hope for the future, and some mourning for those that have, or are, suffering.

Posted in Blog | Tagged , , | Comments Off on Daily Coping 21 May 2021

Tesla and DevOps

That’s how someone described a Tesla recently, talking about how the software keeps changing. I had watched a few videos after I stumbled on this one:

That got me thinking, and writing. I’ve got an editorial on this coming up, but really I was intrigued by the idea that the car would be upgraded, and not by unlocking features, but by adding them.

I wrote before about BMW adding lots of things to the car and letting you unlock them. You could rent heated seats, for example, for a road trip, or a few months. Or rent them in your newly purchased secondhand car, when the previous owner never wanted them. That’s an interesting idea, but it’s simple. We know what’s available, and we pick from the menu of features.

The Tesla thing is more interesting. They are upgrading the car. They have upgraded software to add more range to vehicles. They added sentry mode and dog mode. The change things, which sometimes is annoying for users when the UI moves, but it’s a neat idea.

It’s DevOps in real time and in the real world. Not everything works, but not all changes in cars work. Plenty of mechanical designs find flaws and the last few decades, plenty of car software has had issues. I wish that more companies would adopt the upgradeable car, and make changes to improve things. Simple things, like letting me roll up windows remotely. My BMW had remote locking doors from an app, which I used when I got the airport, went inside and wasn’t sure I’d locked the car, but they stopped some of those features and turned off the wireless update (likely a security issue).

I’m becoming more intrigued by Tesla, and I am considering one for the next car. I wouldn’t have thought that a few years ago, but for some reason the fans are convincing me.

 

Posted in Blog | Tagged , , | Comments Off on Tesla and DevOps

Daily Coping 20 May 2021

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 send a note to a friend you haven’t communicated with this year.

I haven’t seen many people this year, but I have tried to reach out to a few. I took this opportunity to touch base with a couple people in other countries that I haven’t been able to visit and would normally see at some point during the year.

It was good to reach out and have a short email conversation with a few individuals that I enjoy seeing, but haven’t communicated with very much under the pandemic. Part of my coping, however, is the hope that I’ll get the chance to actually see some of these people in the future.

Posted in Blog | Tagged , , | Comments Off on Daily Coping 20 May 2021

Computed Columns for Grouping–#SQLNewBlogger

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

I ran into someone trying to do some grouping for an accounting report. In this case, they had a number of criteria where certain accounts were used to produce groups of values. For example, I might have these criteria:

  • Accounts from 400000 to 490000 are Operating Expenses
  • Accounts from 500000 to 502999 are Personal Expenses
  • Accounts from 503000 to 503999 are Materials and Services

There would be other items, but if I have accounts and values, how do I sum and group in these ways?

There are a few possibilities, but since I might move accounts around, I thought that computed columns might help with grouping here. This post looks are a way you can do this.

Imagine I have some values like this:

CREATE TABLE BudgettoActual
(accountid INT
, budget NUMERIC(10,2)
, actual NUMERIC(10,2)
)
GO
INSERT dbo.BudgettoActual
     (accountid, budget, actual)
VALUES
     (400010, 300, 299),
     (501010, 100, 102),
     (502010, 200, 150),
     (503010, 400, 150),
     (507010, 800, 150)
GO

Now I can use a SUM with a CASE, but that makes a complex query. One way to simplify this for others is to use a computed column in the table that might include my criteria. I can use a CASE statement to create my groupings.

ALTER TABLE dbo.BudgettoActual 
ADD AccountGroup AS CASE
    WHEN accountid>= 400000 AND accountid < 489999 THEN 1
    WHEN accountid>= 501000 AND accountid < 503000 THEN 2
    WHEN accountid>= 503000 AND accountid < 504000 THEN 3
    WHEN accountid>= 507000 AND accountid < 508000 THEN 4
  ELSE 5
  END

With this, I see this in my table:

2021-05-12 11_35_15-SQLQuery5.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (52))_ - Microsoft SQL Server

Now I have these different groups that I can use in a query and group by them. For example, I can get a quick look at my different categories with this code. I’ve put the categories in a CASE in the column list, but it could come from another table.

SELECT
          CASE
              WHEN ba.AccountGroup = 1 THEN
                  'Operating Revenues'
              WHEN ba.AccountGroup = 2 THEN
                  'Personal Expenses'
              WHEN ba.AccountGroup = 3 THEN
                  'Materials and Services'
              WHEN ba.AccountGroup = 4 THEN
                  'Reserves'
          END 'Object'
        , SUM (ba.budget) AS Budget
        , SUM (ba.actual) AS actual
FROM     dbo.BudgettoActual AS ba
GROUP BY ba.AccountGroup;

This gives me a look at my financial numbers quickly.

2021-05-12 11_36_20-SQLQuery5.sql - ARISTOTLE.sandbox (ARISTOTLE_Steve (52))_ - Microsoft SQL Server

Rather than numbers, I could have used the title in the computed column, but that causes issues with ordering. With these numbers, I can choose numbers that are the order I need them in for a report (which can matter for financial reporting).

I’d prefer to use a separate table mapping the AccountGroup to a title and then joining that in my report.

This isn’t the only way to do this, but it is one way to handle complex grouping in a way that can make it easier for clients that might need to query this data.

SQLNewBlogger

This post took me about 10 minutes to write, but about 15 minutes to setup, which might be most of a writing session for a blog. However, it’s a good showcase of a creative way to solve an issue.

Any of you could put together a similar post on a query issue you’ve run into and want to share.

Posted in Blog | Tagged , , | Comments Off on Computed Columns for Grouping–#SQLNewBlogger