Skip to content
Advertisement

Split Characters in a cell to individual columns [closed]

I have a dataset where a column contains 1 and 0 in a single cell which reference security authorities in a software program. I need to split these out into individual columns as these denote (0) No Access and (1) Access

Example:

Column1
01001

Expected Outcome

Column1 Column2 Column3 Column4 Column5
0       1       0       0       1

Appreciate any help on this sql statement to make this happen

Thanks Paul

Advertisement

Answer

With the assumptions proposed by @Stu, a simplified version would be

declare @v varchar(5) = '01001'

select 
  substring(@v,1,1) as column1,
  substring(@v,2,1)  as column2,
  substring(@v,3,1)  as column3,
  substring(@v,4,1)  as column4,
  substring(@v,5,1) as column5
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement