TSQL Pivoting Issue - looking for better approach
问题 This is a T-SQL related question. I am using SQL Server 2012. I have a table like this: I would like to have output like this: Explanation: For each employee, there will be a row. An employee has one or more assignments. Batch Id specifies this. Based on the batch Id, the column names will change (e.g. Country 1, Country 2 etc.). Approach so far: Un-pivot the source table like the following: select EmpId, 'Country ' + cast(BatchId as varchar) as [ColumnName], Country as [ColumnValue] from