ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 254.7k

How to update comment with statment havemulti status where i have more

Feb 24 2021 12:44 AM
How to update comment with statment havemulti status where i have more than one status per part ?

I work on Sql server 2012 I face issue I can't update comment column for every part
when part have more than one status distinct inside and outside
as partid 1202 have multi status inside and outside

so i need to write query update comment where it have more than one status

distinct as part id 1202

but not update part id 1230 because it have two status outside but not

two status it is only one status but repeated

  1. create table #parts  
  2.  (  
  3.  PartId int,  
  4.  FeatureName nvarchar(20),  
  5.  Status  nvarchar(10),  
  6.  Comment nvarchar(100)  
  7.       
  8.  )  
  9.  insert into #parts(PartId,FeatureName,Status,comment)  
  10.  values  
  11.  (1202,'Mounting','Inside',NULL),  
  12.  (1202,'Mounting','Outside',NULL),  
  13.  (1210,'voltage','Outside',NULL),  
  14.  (1215,'voltage','Inside',NULL),  
  15.  (1220,'Mounting','Inside',NULL),  
  16.  (1220,'Mounting','Inside',NULL),  
  17.  (1230,'Mounting','Outside',NULL),  
  18.  (1230,'Mounting','Outside',NULL),  
  19.  (1285,'hold','Inside',NULL),  
  20.  (1285,'hold','Outside',NULL),  
  21.  (1300,'Heat','Inside',NULL),  
  22.  (1300,'Heat','Outside',NULL)  
  23.   
  24. Expected result  
  25.   
  26.  PartId    FeatureName     Status      Comment  
  27.  1202    Mounting          Inside      Have MultiStatus  
  28.  1202    Mounting          Outside     Have MultiStatus  
  29.  1210    voltage           Outside     NULL  
  30.  1215    voltage           Inside      NULL  
  31.  1220    Mounting          Inside      NULL  
  32.  1220    Mounting          Inside      NULL  
  33.  1230    Mounting          Outside     NULL  
  34.  1230    Mounting          Outside     NULL  
  35.  1285    hold              Inside      Have MultiStatus  
  36.  1285    hold              Outside     Have MultiStatus  
  37.  1300    Heat              Inside      Have MultiStatus  
  38.  1300    Heat              Outside     Have MultiStatus

Answers (1)