ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 254.1k

How to separate field partdone to text yes or no or null bas

Mar 11 2020 3:26 AM
How to separate field partdone to text yes or no or null based on position ?

I work on SQL server 2012 and have table parts have two field
  1. partId int  
  2. PartDone nvarchar(50)  
  3.   
  4.   
  5. partId    partDone  
  6. 555444    0012  
  7. 911877    0221  
the length of partDone field is 4 numbers

I need to loop within partDone field

if 0 then no

if 1 then yes

if 2 then null

FinalResult
  1. partId    partDone first  second third  four  
  2. 555444    0012     no      no     yes   null        
  3. 911877    0221     no      null   null  yes  
this field partDone accept only 0 or 1 or 2

and I need to divide them to yes or no or null based on position of every number

What I have tried:

select partId,partDone from Parts

Answers (3)