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

tablename_WriteToDataDestination: Mashup Exception Data Source Error Couldn't refresh the entity...

 Once a Dataflow is created and published on Fabric, got the below error while refreshing the Dataflow. tablename_ WriteToDataDestination: M...