Problems displaying this newsletter? View online.
SQL Server Central
Featured Contents
Question of the Day
The Voice of the DBA
 

Daily Coping Tip

Write a short list of 3 things you feel grateful for and why

I also have a thread at SQLServerCentral dealing with coping mechanisms and resources. Feel free to participate.

For many of you out there working in a new way, I'm including a thought of the day on how to cope in this challenging time from The Action for Happiness Coping Calendar. My items will be on my blog, feel free to share yours.

Coding for the Future

I posted a note on Twitter about some code. In this case, it was the start of a for loop, but with two things in it that I didn't like. The code is shown here:

for ($i = 2011; $i <= 2021; $i++) {

Both the starting point and the ending condition were problematic for me. This code is used in a scheduling application, to populate a dropdown that I used regularly. It's always worked, since about 2017 or 2018, and I had no reason to even think about the algorithm. I assumed the code was something like this:

for ($i = 2011; $i <= year(); $i++) {

In fact, when I had issues on 27 Dec, I assumed that things were coded to the current year and I'd be able to schedule things on Sunday night when I got home. Instead, things still didn't work the first few days of 2022 and I had to get someone to come in from holiday to fix the code. Now it looks back a few years (likely unnecessary) and looks forward one year, as it should.

I don't know why a developer would bother coding anything like this. Get the need to perhaps test something expediently and limit choices, but hard-coding most anything is a poor idea. There ought to be some logic in how or why you choose values, and that logic often can be expressed in code that adapts to situations. I certainly could have lived with only the current year being available, though that still doesn't think through the problem space.

I've seen lots of simple bugs in code over the years that are similar to this one. These often occur because the developers haven't thought through how code might need to adapt to slightly changing situations. Something like a change in the year, or maybe the addition of a time slot for scheduling or a new location added, even a new tax rate. Often I find developers think they have considered the problem given to them, but a little too tightly. They haven't thought about how their code might change if the user requesting the feature has made a mistake.

Writing code that solves a problem and allows for adaptation to likely scenarios is a bit of an art. It can be hard to do, but great developers assume users will need some changes and plan for this in their solution. They also assume users make mistakes in their specifications and they don't hard code anything.

Steve Jones - SSC Editor

Join the debate, and respond to today's editorial on the forums

 
 Featured Contents
Stairway to Advanced T-SQL

Stairway to Advanced T-SQL Level 5: Turning Data On Its Side Using PIVOT Operator

Greg Larsen from SQLServerCentral.com

The PIVOT operator was added to the Transact-SQL language in SQL Server 2005. It allows you to turn your row data on its side, so it can be presented as column data. This is useful when you want take unique column values and have them displayed as column headings, where the column headings are associated with summarized values displayed below each column heading. In this article I will be exploring how to use the PIVOT operator.

External Article

Creating a SQL Server Agent Job to Run Python Scripts in a Virtual Environment

Additional Articles from MSSQLTips.com

In this article we walk through how you can run Python scripts using SQL Server Agent, so you can setup scheduled jobs to run your Python code.

External Article

Automating Flyway Undos

Additional Articles from Redgate

How to auto-generate first-cut undo scripts for every Flyway migration. For every new version of a database created by a Flyway versioned migration, we compare it to a 'source' directory containing object-level build scripts for the previous version. The SQL Compare engine does the rest, producing the associated undo script that will revert the database to the previous version, if required.

Blog Post

From the SQL Server Central Blogs - Identifying Recompile Causes

Grant Fritchey from The Scary DBA

Strictly speaking, a recompile isn’t really a performance tuning problem. In fact, a lot of time, recompiles are desired because they reflect changes in statistics which are likely to...

Blog Post

From the SQL Server Central Blogs - Purging a SQL Server Express Database

Kevin3NF from Dallas DBAs

This is not another IRL post, but rather is more of “Help, my SQL Express database is full!” post. I was contacted by a lawyer that was using a...

 

 Question of the Day

Today's question (by Steve Jones - SSC Editor):

 

Mirroring Endpoint Authentication

I am creating an endpoint for my Availability Group and want to specify Windows authentication. What options do I have for the protocol?

Think you know the answer? Click here, and find out if you are right.

 

 

 Yesterday's Question of the Day (by Steve Jones - SSC Editor)

Amazon RDS

What type of database is Amazon RDS?

Answer: A relational database service for multiple different relational engines

Explanation: As of Dec 1, 2021, this service was available for the following relational database engines:

  • Amazon Aurora
  • PostgreSQL
  • MySQL
  • MariaDB
  • Oracle
  • SQL Server

Ref: Amazon RDS - https://aws.amazon.com/rds/

Discuss this question and answer on the forums

 

 

 

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.


SQL Server 2017 - Administration
Generate scripts with least privilege - How to execute "Generate scripts" option for database with minimum privilege ? I am using "Generate scripts" for "Types of data to script" - Schema only option. There are some confidential data in some database , hence we don't want to give other user data view/modify permission. Is it possible to give a User/login  "view […]
SQL Server 2017 - Development
Case Statement - I am having an error with this code:   select customer_name, order_id, (case when sum(status = 'delivered') = count(*) then 'completed' when sum(status = 'delivered') > 0 then 'in progress' when sum(status = 'submitted') > 0 then 'awaiting progress' else 'awaiting submission' end) as status from customer_order group by customer_name;   error = Msg 156, Level 15, State 1, Server dbrank-tsql, Line 2 Incorrect syntax near the keyword 'when'
Is it possible to migrate a solution from SSMS to SSDT?? - VS 2017, SQL Server 2016 and 2017, is it possible and or making sense to migrate a solution from SSMS to SSDT? The main purpose is to incorporate large solutions with multiple files into TFS that SSMS is not supporting.
SQL Server 2016 - Administration
Tempdb Showplan for user without login - I'm running into the following issue. The stored procedure I need to performance tune uses a user without login. This is needed for row-level security. But the problem I ran into is that I cannot give this user showplan rights in the tempdb database. Does anyone have a solution or workaround for this?
SQL Server 2016 - Development and T-SQL
Complicated insert - I want to insert values from Table1 to Table2 Conditions: when thier is a location with "xx", the row needs to be inserted twice the Empno in table2 is  a primary key with identity seed. Expected Output  
Missing Indexes - We are noticing a lot of I/O latency on our SQL server. Is it common to have a lot of missing indexes? We are trying to narrow down what could be causing all the I/O latency we are seeing. Thanks for any help!  
Administration - SQL Server 2014
Backup SQL database generates error - Hi I have a server running Microsoft SQL 14 on window server 2012. At december 06 it stopped to take backups every night. I got following error message: The operating system returned the error '1(Incorrect function.)' while attempting 'ReadFile' on 'C:\Program Files\Microsoft SQL Server\MSSQL12.OPUS\MSSQL\DATA\OPUSDATA\a488f2a0-564d-44ce-8e57-7d5425d5b798\c55b8372-9595-4dce-9b68-16f5f5466a44\00016be8-000001a9-0005 I have checked if the file in the error message exist […]
No objects listed for "SQL Server performance condition alert"? - Hi All, Facing a weird issue. We are trying to create some alerts in our SQL Server 2014 BI edition. Issue is that, after I chose "Type" as "SQL Server performance condition alert" nothing is listed in the "Object" list box. SQL Server event alerts are working. Issue is only with "SQL Server performance condition […]
SQL Server 2019 - Administration
password expiration policy- should it be enabled? (linked servers/SSRS) - Hi, I would like to ask you for 'best practices' regarding password expiration policy for accounts used by linked servers and SSRS, or other applications. I can see that due to security reasons it makes sense to enforce password policy expiration for all accounts which use SQL server authentication. At the same time, I can […]
Linked server to Unisys DMSII - HI,     I am creating a linked server to Unisys DMSII database. I installed MCP driver and created a ODBC connection. The ODBC was working 2 weeks ago, but now the ODBC connection could not remember the password. If I put the password in the password field and test it, it works, but if […]
SQL Server 2019 - Development
Start Sql server agent job after a trigger - Is it possible to start Sql server agent job after a trigger? what i want to do is after a certain table updates a certain column, then it runs a job that has various sql stored procedures. if not possible at all, is there something similar to this?
The same value across 5 or more columns in a table , How can I write a query -   I got a table with 5 integer columns and one varchar(100) column. Select * from tbl1 where col1 = col2 or ....col5=col4 ..... I dont want to do this. Can we concatenate these fields and somehow comeup with a RegEx or some other way to find the rows that have the same integer values across […]
Trying to print barchart to PDF file using Python within SQL Server ML module - There are likely to be several unrelated errors here, but I'm going to start with the first one what I can get my mind around.  I'm trying to use the "Python within SQL Server" mechanism to generate a barchart to PDF.  I get an error message that I don't have permissions to the directory I'm […]
Reporting Services
accessing a shared data source that is created in report server, by report desig - Hello There, I created a shared data source over SSRS report server web-portal; I am wandering, if it can be used /accessed by report-designer while building a report? I got this concern, because, as I tried to find a way out to access a shared data source by right click on shared data source > […]
Anything that is NOT about SQL!
SSC Fantasy Football 2022 - Placeholder for the 2022 league. Congrats to the 2021 winners: First - Jimbabwe Seahawks - $100 Second - British Bulldogs - $75 Third - Green Machine - $50
 

 

RSS FeedTwitter

This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -