0

I have a field that contains a log of changes. every time adds the date between square brackets.

I need to extract the last bit of the filed after the last ] to put it into a table.

I was trying this but it doesn't work...

select
SUBSTRING(BUG.CloseDescription,0,PATINDEX(']',bug.CloseDescription)) as myString
from Bug

Any ideas?

thanks

Lloyd Powell
  • 18,270
  • 17
  • 87
  • 123

2 Answers2

0
declare @field varchar(100)
set @field = 'test [2012-02-10 10:00] wibble'
select right(@field, charindex('[',@field))

or to get the date

declare @field varchar(100)
set @field = 'test [2012-02-10 10:00] wibble'
select substring(@field, charindex('[',@field)+1, charindex(']',@field)-charindex('[',@field)-1)
Andrew
  • 5,215
  • 1
  • 23
  • 42
0
select
right(BUG.CloseDescription,charindex(']',reverse(BUG.CloseDescription))-1)
from Bug
valex
  • 23,966
  • 7
  • 43
  • 60