In this article, we’ll look at using the built-in PWDCOMPARE function in SQL Server for security testing passwords. While this tool may seem like it exposes a weakness in Microsoft SQL Server because we can test for passwords, it should be of note that an attacker could do the same attack by attempting to login to our database server assuming the attacker was able to access a connection to it. Therefore, this function does not increase the risk of an attack on SQL Server but does help us identify possible weaknesses in our environment so that we can quickly mitigate these risks. In addition, we’ll also combine this with other related tools in SQL Server to help us with logins.
Read more »Languages and coding
Lever T-SQL for Pinpoint Control of ORDER BY in a Stored Procedure
June 1, 2020Introduction
The T-SQL ORDER BY clause sorts SQL Server SELECT statement result sets, and it becomes important when we build stored procedures. Unfortunately, the syntax offers no flexible way to directly control the ORDER BY clause behavior with argument values. This means we don’t have an easy way to control the specific column or columns that the ORDER BY clause sorts. Additionally, SQL Server does not offer a flexible way to directly control the ascending or descending order of any ORDER BY clause column with argument values. Of course, we can certainly hard-code the ORDER BY clause in a stored procedure, but this approach becomes fixed in stone. We could try a dynamic SQL solution, involving a stored procedure code that dynamically builds and executes SQL Server statements inside a stored procedure. However, this technique becomes tricky, and it can lead to SQL injection attacks. Other techniques might rely on CASE statements, and their complexity can become overwhelming as the column count grows. This article spotlights a clean, efficient, pinpoint T-SQL stored procedure technique that directly sorts one, some, or all SELECT statement result set columns. The technique avoids dynamic SQL, and it operates directly in a stored procedure. The article also shows how to set the ascending or descending sort order of specific columns.
Read more »Programmatic access to Power BI PowerShell commandlets
May 25, 2020In this article, I am going to demonstrate how to access the Power BI PowerShell commandlets. In the previous article in this series, we discussed how to programmatically access the Power BI Service using the REST APIs available. PowerShell is one of the most frequently used and preferred ways of automating monotonous manual jobs and scripting those. PowerShell comes integrated with Windows, so it can be easily used from any Windows machine.
Read more »Import XML documents into SQL Server tables using SSIS packages
May 21, 2020This article guides you through importing XML documents into SQL tables using SSIS packages.
Read more »Learn SQL: SQL Server export to Excel
May 20, 2020In the previous article, Learn SQL: SQL Server Pivot Tables, we’ve discussed how to create a report using a PIVOT table query. We’ve created such a report directly in the SQL Server. In this article, we’ll do the same, but this time we’ll use SQL Server export to Excel. So, let’s start.
Read more »The JSON_QUERY() function to extract objects from JSON Data
May 19, 2020In this article, we will explore JSON_QUERY() functions in SQL Server to extract JSON objects and array from the JSON Data.
Read more »An Overview of the XML Task in SSIS Packages
May 18, 2020Introduction
We can use an SSIS package to perform various tasks such as data import, transform, and get output in various formats. Once we launch Visual Studio 2019 and create an integration services project, it shows you various tasks in the SSIS toolbox. In this article, we will explore the XML Task in the SSIS.
Read more »Learn SQL: SQL Server Pivot Tables
May 11, 2020In the previous few articles in this series, we’ve set the foundations on how to create a report. We’ll take one step further and see how to use the SQL Server PIVOT table operator. We’ll start from the simple query and slowly progress towards dynamic SQL and PIVOT. Let’s start.
Read more »Lever T-SQL to dynamically define duplicate SQL Server database table rows
May 11, 2020Introduction
Lever T-SQL to handle duplicate rows in SQL Server database tables article highlighted T-SQL features that detect and handle duplicate SQL Server table rows. The techniques work well, but they rely on fixed duplicate row definitions. This article extends those techniques, showing how to define duplicate rows in a dynamic way.
Read more »Learn SQL: Create SQL Server reports using date and time functions
May 8, 2020In the previous two articles of this series, we’ve discussed how to create a report and how to use built-in date and time functions. Today, we’ll join these two together and analyze some interesting queries we could use while creating more complex SQL Server reports where date and time functions are used to create reporting categories.
Read more »Extract scalar values from JSON data using JSON_VALUE()
May 5, 2020In this article, we will explore JSON_VALUE() function in SQL Server to extract scalar values from JSON data.
Read more »Modifying JSON data using JSON_MODIFY() in SQL Server
May 4, 2020This article explores JSON_MODIFY() function to modify JSON Data in the SQL Server.
Read more »How to UPDATE from a SELECT statement in SQL Server
April 29, 2020In this article, we will learn different methods that are used to update the data in a table with the data of other tables. The UPDATE from SELECT query structure is the main technique for performing these updates.
Read more »Lever T-SQL to handle duplicate rows in SQL Server database tables
April 24, 2020Duplicate rows in a SQL Server database table can become a problem. We will see how we can find and handle those duplicate rows using T-SQL in this article.
Read more »Python scripts to split and concatenate strings
April 23, 2020This article gives an overview of Python Script functions to split strings and string concatenation functions.
Read more »SQL Server JSON functions: a bridge between NoSQL and relational worlds
April 22, 2020In this article, we will explain what JSON is, what are the SQL Server JSON functions introduced in 2016, how to index JSON values, and how to import JSON data into SQL tables.
Read more »Learn SQL: SQL Server date and time functions
April 21, 2020So far, we haven’t talked about SQL Server date and time functions. Today we’ll change that. We’ll take a close look at the ones most frequently used and mention all other date and time functions as well. This will be also the first step to create reports, including date and time functions. We’ll do that in upcoming articles in this series.
Read more »Learn SQL: Create a report manually using SQL queries
April 16, 2020In the previous two articles, we’ve practiced SQL queries and went through a few more examples. Today we’ll use SQL queries and create a report from scratch. We’ll start from the simplest possible query and finish with the query returning the actual report data.
Read more »Pagination in SQL Server
April 14, 2020Pagination is a process that is used to divide a large data into smaller discrete pages, and this process is also known as paging. Pagination is commonly used by web applications and can be seen on Google. When we search for something on Google, it shows the results on the separated page; this is the main idea of the pagination.
Read more »How to update the T-SQL Toolbox database
April 6, 2020Introduction
In an earlier article, Solve Time Zone, GMT, and UTC problems using the T-SQL Toolbox database, I described T-SQL Toolbox, a free, open-source SQL Server database that handles time zone, date, and time calculations in a clean and efficient way. Available here at the CodePlex Archive, and here at GitLab, T-SQL Toolbox relies on time zone and time zone adjustment data in its two tables for many of its own calculations. However, T-SQL Toolbox does not update that data. I built primitive C-Sharp and VB.net applications that extract the latest time zone and time zone adjustment data from the Windows registry, and I discussed those applications in that earlier SQL Shack article. In the article, I explained that we can build SQL Server UPDATE statements with this extracted data, and then update the T-SQL Toolbox tables. This article describes a better approach and a better solution.
Read more »Learn SQL: SQL Query examples
March 31, 2020In the previous article we’ve practiced SQL, and today, we’ll continue with a few more SQL examples. The goal of this article is to start with a fairly simple query and move towards more complex queries. We’ll examine queries you could need at the job interview, but also some you would need in real-life situations. So, buckle up, we’re taking off!
Read more »Working with SQL Server ROWCOUNT
March 30, 2020In this article, we will discuss the SQL Server @@ROWCOUNT and ROWCOUNT system objects by going through practical examples that cover most of these system objects usage.
Read more »Learn to write basic SQL Queries
March 27, 2020Essentially, SQL language allows us to retrieve and manipulate data on the data tables. In this article, we will understand and gain the ability to write fundamental SQL queries. At first, we will take a glance at the main notions that we need to know about in order to write database queries.
Read more »INSERT INTO T-SQL Statement in SQL Server
March 27, 2020In this article, we will go deeply through the INSERT INTO statement by showing the different syntax formats and usage scenarios for that statement.
Read more »Learn SQL: Practice SQL Queries
March 25, 2020Today is the day for SQL practice #1. In this series, so far, we’ve covered most important SQL commands (CREATE DATABASE & CREATE TABLE, INSERT, SELECT) and some concepts (primary key, foreign key) and theory (stored procedures, user-defined functions, views). Now it’s time to discuss some interesting SQL queries.
Read more »