Tag : sql server 2016


Get error column name in Data Flow Task in SSIS

How to get error column name and error description in Data Flow Task in SSIS

During execution of an SSIS package, when a bad row comes in the data flow task, the task gets failed. However, most of the components (source, transformation, and destination) in the data flow task exposes an error output path which can be configured to redirect these invalid records to the error output path and then we can log these redirected bad records using a destination component. Once all these bad records get logged, we can investigate the root cause of the errors, fix them, and then these bad rows can be reintroduced again.

The error output path in the data flow task contains two four byte int columns, ErrorColumn and ErrorCode, which represent the lineage id of the error column and the error code respectively. The values in both these columns are numeric which … More


STRING_SPLIT function – SQL Server 2016 1

Finally, STRING_SPLIT function, one of the most awaiting feature for a long time, has been introduced by Microsoft. In SQL Server 2016, now, we have a built-in system function to split a string with a specified separator.

Earlier, whenever we had to map a denormalized string (e.g. comma separated string values) with the values stored in a table column (normalized values) , we had to create a table valued function which could create a table from a given string value by splitting it using predefined separator. The problem with creating our own function to split the string was its performance, especially if we were not using either a CLR function or an highly optimized SQL function.

One of the most common scenario where we need this functionality very frequently is whenever we need to deal with SSRS’s multi value parameters. Reporting services supplies a comma separated string value to the … More


DATEDIFF and DATEDIFF_BIG – SQL Server 2016

We are already familiar with DATEDIFF function introduced in the very initial version of SQL Server. But, in SQL Server 2016, Microsoft has introduced DATEDIFF_BIG function which can be used to compute the difference between two given dates in terms of the given date part. In this post, we are going to explore the use of the DATEDIFF_BIG function.

Lets have a look on the syntax of both these functions:

Syntax:

DATEDIFF

DATEDIFF(<datepart>, startdate, enddate)

DATEDIFF_BIG

DATEDIFF_BIG(<datepart>, startdate, enddate)

Difference between DATEDIFF and DATEDIFF_BIG function

In above syntax, we can see that both the functions have similar syntax and any of them can be used to get the difference between two dates. However, these functions have different return types. DATEDIFF function returns an integer value as a difference between two dates, whereas DATEDIFF_BIG function returns a big integer value as a difference.

The range of the integer value in … More


It’s time to install SQL Server 2016

Microsoft has launched the SQL Server 2016. We can download and install it from here. However, when we start installation of SQL Server 2016, we can see some installation changes there. Prior to SQL Server 2016, “SQL Server Management Studio (SSMS)” was a part of the feature list of main SQL Server installation (which starts after clicking on “New SQL Server stand-alone installation or add features to an existing installation“) but now it is available on a separate install. Below is the screen shot of the feature selection list of SQL Server 2016 and SQL Server 2014:

SQL Server 2016 Feature list 2016 vs SQL Server 2014 Feature List

SQL Server 2016 Feature list 2016 vs SQL Server 2014 Feature List

In above image, we can see that the management tools was a feature of the core SQL Server installation process in SQL Server 2014 (right side image) but in SQL Server 2016 (left side image), it is not … More


Querying temporal table data

We have discussed what is a temporal table, how we can create it, and what are the limitations of a temporal table. We have also discussed how we can convert an existing table to a temporal table in our previous posts.

In this post “querying temporal table data” we are going to learn how to query the time varying data from a temporal table.

In SQL Server 2016, we have a new clause FOR SYSTEM_TIME, which has four new sub clauses to query temporal table data:

  1. AS OF <datetime>
  2. FROM <start_datetime> TO <end_datetime>
  3. BETWEEN <start_datetime> AND <end_datetime>
  4. CONTAINED IN (start_datetime, end_datetime)

Let’s create a temporal table with dummy data to query with FOR SYSTEM_TIME clause and its sub clauses with examples. Below script is used to create a temporal table and to insert few dummy rows in the table with SQL Server default datetime value (1900-01-01) … More


Convert existing table to temporal table 3

In the previous post, we have discussed the temporal table, which is introduced in SQL Server 2016 to store the time varying data (current data and the data change history along with the time period). There, we have also learnt how we can create a temporal table from scratch.

In this post “Convert existing table to temporal table“, we are going to learn how we can convert an existing table to a temporal table. For the demo purpose we are using a dummy employee table, created with a very small subset of the data taken from HumanResources.Employee table of adventure works database.

Below is the dummy table which needs to be converted in a temporal table:

Existing employee master table

Existing employee master table

We can use below script to create the above sample table with the data for demo purpose:

--Create demo employee master table
CREATE TABLE dbo.EmployeeMaster
(
BusinessEntityID 
More

Temporal Table in SQL Server 1

In this post we are going to discuss “Temporal Table”, a new feature introduced in SQL Server 2016. Lets start this post “Temporal Table in SQL Server” with the definition of temporal table.

Temporal Table facilitates inbuilt support for data change tracing along with the time period in a table. It holds the current as well as historical data to determine the values of a record at any given period of time. Temporal table uses a pair of tables; current table and an associated history table, to store current and historical data respectively. It uses two system columns of data type datetime2 to record start time and end time in both tables (current and history) to enable record versioning.

We can easily manage the data change history in a table using temporal tables which was a bit cumbersome and manual task in the previous versions of Microsoft SQL Server. Temporal … More