SQL - Concatenate multiple column values
Yesterday I got one requirement to concatenate multiple values of same column into one row based on the specified group. Initially I tried it with MS-Excel but it failed suddenly I switched my method to SQL server and finished the job in no time. I thought it will be better to share the code for future use. Requirement Due to restrictions in giving the actual requirement, masked the details and also reduced the total number of columns. In actual requirement there are millions of records are there and here I reduced the records to 6 for easy understanding. Look at the figure F 0.1 Fig 0.1 for the same customer and city there are multiple product serials and the output result should be like Fig 0.2 Fig 0.2 Solution Create table with identity column in SQL server and insert the raw data into the table. Identity column helps us to go through the each rows in the table. CREATE TABLE RequirementData ( ctr INT IDENTITY (1,1), [Customer] [ NVARCH