Select number from Master. Spt_values with (nolock) where type= ' P '/** explained: Master. The corresponding Number field value for the Spt_values table's field value is p from 0-2047*/--1. Converting a string to a column shows if OBJECT_ID (' TB ') is not null drop table TB go CREATE TABLE TB ([numbered ] varchar (3), [Product] varchar (2), [quantity] int,[unit Price] int,[amount] int,[serial number] varchar (8)) insert into TB ([number],[product],[quantity],[Unit price],[amount],[Serial number] Select ' 001 ', ' AA ', 3,5,15, ' 12,13,14 ' Union allselect ' 002 ', ' BB ', 8,9,13, ' 22,23,24 ' Go SELECT [number],[product],[quantity],[Unit price],[amount], SUBSTRING ([Serial number],b.number,charindex (', ', [serial number]+ ', ', B.number)-b.number) as [serial number] from TB A with (NOLOCK), Master: Spt_values B with (NOLOCK) where b.number>=1 and B.number
SQL Server in master: Application of Spt_values