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

Daily Coping Tip

Recall three things you’ve done that you are really proud of

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.

The Challenges of Working Under Quarantine

It's been nearly two months since the Redgate Software offices closed. I am not normally in the office, but I did cancel a trip that I normally would have taken to touch base with a number of teams. That's a minor change for me, but a still a change. It's much less than the change for most other people, and by now, I expect many people have somewhat adapted to working at home.

Working at home under this pandemic isn't the same as working remotely. This has been forced upon us, and I agree with Scott Hanselman. Like me, he's worked remotely for years, and this is different. We have kids, partners, roommates, and others around. We can't easily change our scenery or engage in some of our usual activities. This is stressful, overwhelming, upsetting, disconcerting, and more.

Some of you might have accepted this and are learning to work in a new way. Some are coping, but expecting to go back to normal at some point. Some of us are getting much less work done, which adds another level of stress. Performance reviews, and the inevitable comparison with others will weigh on our minds. Whether we go back to normal soon or not, companies will add and remove staff. There are new projects to tackle, raises to award, and all the regular work of running a company.

This is a difficult time for all, and most of us are experiencing life in our own unique ways. Our view of the world, of coping and getting our daily work done is much different than our co-workers. Even if we appear to be the same people, we aren't. We may react differently day to day, and there may not be a good explanation.

This is not the same as remote work, and I hope managers understand that. It is important that we all appreciate that our view of any big or little thing at work is not necessarily the same way others view the same action. A daily standup meeting might seem like a little thing to you, but perhaps it's exam day for someone else's child and they can't focus, or maybe not even attend.

Be kind, be more flexible, and be more understanding. You never know what someone else might be dealing with in their life today.

Steve Jones - SSC Editor

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

 
 Featured Contents

The Basics of Using a Sequence as a Table Default

Steve Jones - SSC Editor from SQLServerCentral

The Sequence object is a way of auto generating a numerical value in some order automatically. This object can be used as a default for a table column, and this articles shows how this can be implemented.

Rewiring Your Culture for an AI-Augmented Future with Intelligent DataOps

Additional Articles from SQLServerCentral

Is your organization—and your data team—ready to embrace an AI-augmented future?

From the SQL Server Central Blogs - Data Bits – Episode 8 – Chrissy LeMaire

Kevin3NF from Dallas DBAs

Microsoft Data Platform and PowerShell MVP, Chrissy Lemaire (b|t) sat down with us in the virtual studio Saturday, and we had a blast getting to know her! Quotables: “This...

From the SQL Server Central Blogs - Which Azure Data Platform service should I choose?

Daniel Janik from Confessions of a Microsoft Addict

So you’ve decided to use Azure for your existing or new data project? This blog series is focused on choosing the right technology for your project. It’s tough right?...

 

 Question of the Day

Today's question (by Greg Larsen):

 

Inlining Scalar UDFs

Scalar user defined functions (UDFs) can cause performance issues that can often be difficult to troubleshoot. Microsoft introduced a new 2019 feature called T-SQL Scalar UDF Inlining that can improve performance of some of these functions without changing any of your code. Which of the functions can take advantage of this feature? (choose 3)
--Function 1
CREATE OR ALTER FUNCTION dbo.GetRating_1(@CustomerID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 
DECLARE @Rating VARCHAR(20);
SELECT @Rating = Rating 
FROM Customer 
WHERE CustomerID = @CustomerID;

RETURN @Rating;
END
GO

CREATE OR ALTER FUNCTION dbo.GetRating_2(@CustomerID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 
DECLARE @Rating varchar(20);
IF @CustomerID % 4 = 0 BEGIN 
SET @Rating = 'Diamond';
END
ELSE IF @CustomerID % 4 = 1 BEGIN
SET @Rating = 'Gold';
END
ELSE IF @CustomerID % 4 = 2 BEGIN 
SET @Rating = 'Silver';
END
ELSE IF @CustomerID % 4 = 3 BEGIN 
SET @Rating = 'Bronze';
END

RETURN @Rating;
END

GO

--Function 3
CREATE OR ALTER FUNCTION dbo.GetRating_3(@CustomerID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 
DECLARE @Rating varchar(20);
DECLARE @RatingID INT;

SELECT @RatingID = RatingID 
FROM Customer
WHERE CustomerID = @CustomerID;

IF @RatingID = 0 BEGIN 
SET @Rating = 'Diamond';
END
ELSE IF @RatingID = 1 BEGIN
SET @Rating = 'Gold';
END
ELSE IF @RatingID = 2 BEGIN 
SET @Rating = 'Silver';
END
ELSE IF @RatingID = 3 BEGIN 
SET @Rating = 'Bronze';
END

RETURN @Rating;
END


GO

--Function 4
CREATE OR ALTER FUNCTION dbo.GetRating_4(@CustomerID INT)
RETURNS VARCHAR(20)
AS
BEGIN
   DECLARE @Ratings TABLE(RatingID INT, RatingDesc  varchar(20));
   DECLARE @Rating VARCHAR(20);

   INSERT INTO @Ratings(RatingID, RatingDesc)
   SELECT RatingID, RatingDesc
   FROM Rating;

   SELECT @Rating = R.RatingDesc
   FROM Customer  AS C
   JOIN @Ratings  AS R ON C.RatingID = R.RatingID
   WHERE CustomerID = @CustomerID;

   RETURN @Rating;

END

GO

--Function 5
CREATE OR ALTER FUNCTION dbo.GetRating_5(@RatingID INT) 
RETURNS VARCHAR(20) 
AS 
BEGIN 

DECLARE @ID INT = 0;
DECLARE @Rating varchar(20);

WHILE @ID <> @RatingID BEGIN 
SET @ID = @ID + 1;
END;

SELECT @Rating = RatingDesc 
FROM Rating 
WHERE RatingID = @ID;

RETURN @Rating;
END
         

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)

A chart of costs in R

I have this dataframe in R:

> head(sales)
        Date Day    Month Year Customer_Age      Age_Group Customer_Gender
1 2013-11-26  26 November 2013           19    Youth (<25)               M
2 2015-11-26  26 November 2015           19    Youth (<25)               M
3 2014-03-23  23    March 2014           49 Adults (35-64)               M
4 2016-03-23  23    March 2016           49 Adults (35-64)               M
5 2014-05-15  15      May 2014           47 Adults (35-64)               F
6 2016-05-15  15      May 2016           47 Adults (35-64)               F

I am looking to get this histogram of unit costs:

Hiistorgram of unit costs

What should I run to get this?

Answer: hist(sales$Unit_Cost)

Explanation: A quick histogram is from the hist() function. Ref: hist() - https://www.datamentor.io/r-programming/histogram/

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
Old, unnecessary SQL Server windows updates keep failing - any ideas? - Background My organization tightly controls what’s on our internal windows update server. The version of SQL Server that I have installed is Microsoft SQL Server 2017 (RTM-CU20) (KB4541283) - 14.0.3294.2 (X64)   Mar 13 2020 14:53:45   Copyright (C) 2017 Microsoft Corporation  Developer Edition (64-bit) on Windows 10 Enterprise 10.0 (Build 17134: ) (Hypervisor) For some […]
One of six 2017 instances offline - Always On. - Did patch Tuesday yesterday across 6 UCS blades. Servers are 2019 datacenter in a cluster. Each blade has 4 instances so 4 availability groups of 6 members each. One of the 2017 instances is in a bad state. I've tried a repair, I've tried removing updates (even though the other 5 prod blades are fine, […]
SQL 2017 AGL - only accessible locally - Hi, I've got 2 x SQL 2017 CU20 (Dev edition) boxes in a Windows cluster with an AG and listener (non readable sync secondary). The DBs are synchronised and the AGL is contactable through SSMS on the primary server when I'm RDPd on. The SPN is set up for the AGL name with the SQL […]
SQL Server 2017 - Development
Bulk Insert & link relationship between inserted row - Hi, Let me elaborate with example:- I having an existing TableA with below sample column & data Date                             Amount                 Category               Name 2018-01-01                […]
SQL Server 2016 - Development and T-SQL
CTE left join not giving me correct result - Hello, Why is the Left Join with a CTE giving me wrong results? I want to know which Emails are not in Table B using their UserIDs Instead it's giving me all the records from CTE and Null values from the Table B. What am I doing wrong? Many thanks. ; With CTE as ( […]
Encryption table and saving in 2016 - Hi, How would you encrypt data from multiple tables and save in a temp tables using a script (tsql)? please share general logic in sql 2016 version. Should we use always on encryption? or something else and then also how do you decrypt the data from the same temp table and save those in the […]
SQL Server 2019 - Administration
Queries run by a particular login or Database user in SQL Server 2016 - Hello, Is there a way in SQL Server to find out which queries were run by particular login in SQL Server and on which databases? If somebody can provide a script, that will be great. Thanks in advance
Trouble installing latest version of SSMS - Last night I went to the control panel and removed any programs that had 'SQL' in its name.  That was the 2017 version of SSMS.  I wanted to start fresh.  I downloaded SSMS 18.  I'm not sure of the server name, so I tried to find it here: https://docs.microsoft.com/en-us/sql/ssms/tutorials/ssms-tricks?view=sql-server-ver15#find-the-error-log-location-if-you-cant-connect-to-sql-server under the section titled "Find the […]
SQL Server 2019 - Development
Function issue with union (two databases) - I want this function to  retrieve the latest buyer from two databases db1 and db2. It worked for a single db.    Now I try to use UNION to query both dbs an get the latest of the two It won't accept this function "Select statements included within a function cannot return data to a […]
Export sql results to csv -   Hi all, Hopefully you can help me. I have created a sql job which returns some results and then exports it to a csv file. But each column is merged into one cell. The way I have done this is using the sqlcmd feature as per the below: sqlcmd -i Is there […]
How to use stored procedure result set into a script task in SSIS - Hello, guys! I created a SSIS package in Visual Studio Community 2019: Everything is working fine, but I don't know how to pass the data from "Commutations" (SQL Task) to "Net Present Value" (Script Task). Basically, "Commutations" generates a result set that I'm passing to a SSIS object variable. This result set has a couple […]
Pivot Table Problem - I am having a huge brain fart on how to accomplish what I want. I want to pivot the attached set of data (sql file) to look like this (I know its an image but I am not savy enough to plop an actual result set in here). The attached file creates a temp file […]
Integration Services
Execute Powershell Script from Script Task - Has anyone managed to execute a PoSh script from within a Script Task? When I started looking at this, it seemed like it would be straightforward enough and the process is described here. But ... the DLL which that article refers to (and which appears to be necessary to execute PoSh from C#) is called […]
COVID-19 Pandemic
Daily Coping 21 May 2020 - Today’s tip is to reflect on what makes you feel really valued and appreciated. My thoughts: http://voiceofthedba.com/2020/05/22/daily-coping-22-may-2020/
Daily Coping 20 May 2020 - Today’s tip is: Hand-write a note to someone you love and send them a photo of it. http://voiceofthedba.com/2020/05/20/daily-coping-20-may-2020/
 

 

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

 

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