Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace only some underscores
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic
Starting Member

4 Posts

Posted - 02/21/2014 :  15:58:51  Show Profile  Reply with Quote
I have a column with value


I need to replace the middle underscores so that it displays it as date i.e.


Can some one please suggest a simple update query for this.

The Number of Underscores would be same for all the values in the column but the length will vary for example some can have


Flowing Fount of Yak Knowledge

6065 Posts

Posted - 02/21/2014 :  16:07:42  Show Profile  Reply with Quote
Here's one ugly way:

select stuff(stuff(s, idx+3, 1, '-'), idx+6, 1, '-')
from   (
       select s, patindex('%_[0-1][0-9]_[0-3][0-9]_20[0-2][0-9]_%', s) idx
       from   (
              select 'AAAxZZZZ_7890_10_28_2014_123456.jpg' s union all
              select 'AAA_q10WRQ_001_10_28_2014_12.jpg'
              ) d
       ) d



this version will only work with dates between years 2000 an 2029

Be One with the Optimizer

Edited by - TG on 02/21/2014 16:30:43
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000