title: Convert julian date to date in sql server
body: <p>I want to convert the julian date in a date format. 
  Below, please find an example to create my error. All my dates have 5 digits I need to convert.</p>
  <pre><code>create table #test (dateR int)
  
  insert into #test (dateR)
  values (39596),(39596),(39595),(39595),(39593),(39592),(39592),(39589),(38104),(38104),(37957)
  
  SELECT * from #test
  
  select *
      , dateadd (year, dateR/1000 - 1900, dateR %1000 - 1) as Rd
  from #test
  </code></pre>
  <p>Getting the error:</p>
  <blockquote>
  <p>Msg 517, Level 16, State 1, Line 2 Adding a value to a 'datetime'
  column caused an overflow.</p>
  </blockquote>
  <p>Also tried:</p>
  <pre><code>SELECT DATEADD(dd, CONVERT(int, RIGHT(dateR,3)) - 1, CONVERT(datetime,SUBSTRING(dateR,1,2)+'0101', 212))
  </code></pre>
  <p>This returns:</p>
  <blockquote>
  <p>Msg 8116 level 16 state 1 line 1 nullArgument data type int is invalid for argument of substring function</p>
  </blockquote>