简体   繁体   中英

SQL Server : query to convert all row values of a particular column into separate columns

I have a table with large number of rows. I want to select all values of one particular column and create separate column for each unique value.

For example :

在此处输入图片说明

into something like this :

在此处输入图片说明

SELECT 
  left_side  = RTRIM(SUBSTRING(col, 1, CHARINDEX('->', col)-2)),
  right_side = LTRIM(SUBSTRING(col, CHARINDEX('->', col) + 2, 4000))
FROM dbo.table;

hi you can use built in functions Left, Right or CHARINDEX etc.

Hope so this example could help

Example one

Example two

thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM