ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 281.3k

How to update colum serial where is null by max+1 ?

Mar 10 2021 3:28 AM

I work on SQL server 2012 I face issue i can't update column serial by max + 1
where is have null value on on serial column
partnumber is unique on table
so i need to get max number from serial and increment it by 1
then assign it to null on serial column

meaning any partnumber is unique and have null on serial
must have unique number on serial by max number on serial +1

for every part number
  1.  create table #test  
  2.  (  
  3.  partNumber  nvarchar(200),  
  4.  serialNumber  int  
  5.  )  
  6.  insert into #test(partNumber,serialNumber)  
  7.  values  
  8.  ('nna5',9),  
  9.  ('nfggg',20),  
  10.  ('ddfg',10),  
  11.  ('llm',NULL),  
  12.  ('109',NULL),  
  13.  ('8654',NULL),  
  14.  ('1234',30)  
  15.   
  16. expected result  
  17.   
  18. partNumber serialNumber  
  19. llm 31  
  20. 109 32  
  21. 8654 33  
 

 


Answers (5)