ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 254.1k

How to write update statement to table statusvalues where chemical id

Sep 2 2020 7:58 PM
How to write update statement to table statusvalues where chemical id have more than one chemical status ?
I work on SQL server 2012 I face issue ; I can't update status on table statusvalues where chemical id have more than one status
as example
1241 must update status "chemical id have multiple status" because chemicalid have 2 status Rohs and china
1600 not update status because it have only one status as LifeCycle .
  1. create table #chemical  
  2. (  
  3. chemicalId int,  
  4. PartId int,  
  5. chemicalStatus nvarchar(50)  
  6. )  
  7. insert into #chemical(chemicalId,PartId,chemicalStatus)  
  8. values  
  9. (1241, 2250,'Rohs'),  
  10. (1241, 2700,'Rohs'),  
  11. (1241, 2900,'China'),  
  12. (1600, 2950,'Lifecycle'),  
  13. (1600, 3000,'Lifecycle')  
  14. create table #statusvalues  
  15. (  
  16. chemicalid int,  
  17. status nvarchar(50)  
  18. )  
  19. insert into #statusvalues(chemicalid)  
  20. values  
  21. (1241),  
  22. (1600)  
Expected result :
  1. chemicalid     status  
  2. 1241             chemical id have multiple status  
  3. 1600             NULL  

Answers (1)