Maggie on November 23rd, 2017 back in Ohio. She’s still with us, but skinnier, naps more, bites about the same
Jerry Ritcey
A comic book reading, jazz trombone playing, SQL Server database and data engineering ex-Nova Scotian
Wednesday, November 23, 2022
Thursday, October 27, 2022
Comma last or Comma first, what is the official Rule?
From the beginning of time, January 1st, 1900, people have asked, "Should I use commas at the end of column names, or at the start?
-- English Majors
SELECT
FirstName,
MiddleName,
LastName,
EmployeeNo,
SeniorityDate,
JobTitle,
Active
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
-- Programmers
SELECT
FirstName
,MiddleName
,LastName
,EmployeeNo
,SeniorityDate
,JobTitle
,Active
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
The latter has a few advantages. You can comment out a column while writing it without having to edit near the actual column name, so it's faster to add columns in the middle. You can add columns to the end of it very easily by just preceding them with a comma. The English major method would mean you have to add a new comma to the penultimate column each time you add a new one to the end. Commenting is likewise simpler with the comma-first method. I think the final word in this debate should be a mournful shrug. Do what you prefer as long as it's not an unreadable mix. There is also the school of thought of stacking columns horizontally when you have an unworldly number of them like...
select
FirstName,MiddleName,LastName,EmployeeNo,SeniorityDate, --5
JobTitle,Active --7
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
etc.
I do think adding line numbering will help preserve the already shaky sanity of those coming later to debug. Just every 5 lines or so should be enough. And as far as the comments go - I'd kind of prefer to see them on their own lines.
select
FirstName,
MiddleName,
LastName,
EmployeeNo,
SeniorityDate, --5
-- 10/1/2021 Kim F. This is the new WorkdayTitles, not the ones from ToFu
JobTitle,
Active,
ManagerEmpployeeNo,
CostCenter,
SecurityGroup --10
FROM Employees
WHERE active=1
ORDER BY LastnName,FirstName;
etc.
I know comma-first has it's advantages, but if you ever need to present the list of fields to...normies outside of the great Database Kingdoms, comma after will convince them you are mostly human.
Let us speak of this no more.
Where I am on social media?
Since Musk owns twitter now, trying to migrate to other media. Aside from this blog I'll have a few.
Which will I use? I mostly was reading anyway. No idea.
Wednesday, May 25, 2022
SQL Stars twitter list
Here's a link to a twitter list I made for data or SQL obsessed folks called "SQL Stars".
https://twitter.com/i/lists/1236006145996673024
Many of these people are so smart it actually scares me. I'l have to check on it sometimes to make sure no one is just advertising stuff or started selling crypto - but these aer mostly regualr data folks who sometimes post about data. I will not remove someone for non-data posts especially if they post cats or dogs. I tweet here, to be fair, I mostly just retweet; https://twitter.com/jerryritcey
What's new in SQL Syntax in SQL Server 2022
Found a neat article on new syntax in 2022 by Aaron Betrand
Most exciting one might be DATE_BUCKET, which may eliminate the need to roll your own magic dates to find things like first of this month, first of last month, five minute intervals, into one command. One quote of a useful feature combining two new commands; "
BONUS
We can combine DATE_BUCKET
and GENERATE_SERIES
to build a contiguous series of date/time values. I often see people struggle to build a full data set when they are reporting on intervals where not all intervals are populated. For example, I want hourly sales figures across a day but, if we're selling something like cars, not every hour will always contain a sale"