Split Comma Separated Values in a Column to Rows in SQL...

Lets assume a scenario where the Employee table contains information for all the Managers and Users. It will contains the relevant branch codes for each Employee.
Managers will have multiple branch codes and Users will have single branch code.
Sample data will be as shown below.

To achieve this STRING_SPLIT function can be used. This is available from SQL Server 2016 version.
Sample SQL Query is as below

SELECT EmpId, EmpName, value AS BranchCode FROM dbo.Employee CROSS APPLY STRING_SPLIT(BranchCode,',')

The query output is as below


Hope this will be helpful...



No comments:

Post a Comment

How to run UPDATE/INSERT/DELETE Statements on Azure SQL Database in Microsoft Fabric Notebook...

You can run UPDATE/INSERT/DELETE Statements on Azure SQL Database in Microsoft Fabric Notebook using Python SQL Driver - pyodbc.  For the Fa...