title: Use Row_Number() in case statement in sql server
body: <p>I Left Joined 2 table Table A and Table B and the output is below which is correct</p>
  
  <pre><code>select a.id,b.OS_ID from TableA left join TableB
  on a.id=b.id
  </code></pre>
  
  <p>What I want to achieve is replacing NULL with 51 and 52.</p>
  
  <p>If I run this </p>
  
  <pre><code>Declare @OSID int
  set @OSID = (select max(os_ID) from OS_Master)
  </code></pre>
  
  <p>It will give me output as 50, Then I want to increment by 1 for the next entry and replace the NULL value </p>
  
  <p>ID  OS_ID<br>
  1   1<br>
  1   14<br>
  1   NULL<br>
  1   NULL</p>
  
  <p>If I do this:</p>
  
  <pre><code>Declare @OSID int
  set @OSID = (select max(os_ID) from OS_Master)
  select ROW_NUMBER() over (order by os_ID) + @OSID from OS_Master 
  </code></pre>
  
  <p>It works fine, ROW_NUMBER() starts from 51, But If I incorporate it with the join like</p>
  
  <pre><code>select a.ID,case when b.OS_ID is null then (select ROW_NUMBER() over (order by b.os_ID) + @OSID ) 
  else b.OS_ID END    from TABLEA a
  left JOIN TABLEB  b
  on a.ID=b.ID
  </code></pre>
  
  <p>It shows 51 for both the NULL records, How to get 51,52 ans so on in my query</p>