0

I have a varchar column which has data like ABCDE1, the first five characters will be alphanumeric.

I would like to add a hyphen for all records after fifth character

ABCDE-1 

How can I achieve using an update script in SQL Server?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Cork Kochi
  • 1,783
  • 6
  • 29
  • 45
  • 2
    You write code. Start by reading here: https://msdn.microsoft.com/en-CA/library/ms181984.aspx – Marc B Oct 13 '16 at 16:58

1 Answers1

4

Use STUFF function

Select STUFF(varchar_col,5+1,0,'-')
From yourtable

To Update

Update yourtable Set varchar_col = STUFF(varchar_col,5+1,0,'-')
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172