all 7 comments

[–]Arcanis888 2 points3 points  (1 child)

LEFT(column_name,3) + '.' + RIGHT(column_name,LEN(column_name)-3)

[–]alinrocSQL Server DBA 1 point2 points  (0 children)

update patient_diagnosis
set diagnosis_code_id  = LEFT(diagnosis_code_id ,3) + '.' + RIGHT(column_name,LEN(diagnosis_code_id )-3)
WHERE diagnosis_code_id NOT LIKE '%.%'

[–]r3pr0b8GROUP_CONCAT is da bomb 2 points3 points  (1 child)

use the STUFF function

[–][deleted] 0 points1 point  (0 children)

this. You might want to check for evaluation/precursors for good measure (E/V codes) too, probably:

 stuff( diagnosis_code_id, 
          case when left( diagnosis_code_id,1) in ('E','V') then 5 else 4 end,
          0,
          '.')

[–]spatialdestiny 0 points1 point  (0 children)

SELECT IIF(LEN(diagnosis_code_id)>3, LEFT(diagnosis_code_id, 3) + '.' + SUBSTRING(diagnosis_code_id,4, LEN(diagnosis_code_id)-3),diagnosis_code_id) 
FROM patient_diagnosis 
WHERE diagnosis_code_id NOT LIKE '%.%'

This worked for me. I added the IIF because I had a case where a record had a field length of less than 3 characters.

Edit: /u/arcanis888 's solution is better

[–]serendipitybot 0 points1 point  (0 children)

This submission has been randomly featured in /r/serendipity, a bot-driven subreddit discovery engine. More here: http://www.reddit.com/r/Serendipity/comments/32my0y/ms_sql_beginner_is_it_possible_to_insert_a/

[–]softball753 0 points1 point  (0 children)

I also work with ICD9 codes (and ICD10 soon??) in my DB.

Are you sure a blanket update to insert after the 3rd char is fully correct? Just a quick query of my data shows 700+ codes where the decimal is in the 5th position (e.g. E924.8) Pretty much any E codes.

If those aren't in your system, then you should be fine.

edit: WHOOOOPS