copy part of string from one column into another
I've got a column with some string data that somew开发者_C百科here has 'T##' (## being a two digit number) I want to copy this into another column, how do I do that?
something like this:
abc-T03-def
-> 03
For Microsoft SQL Server:
update YourTable
set NewColumn = substring(OldColumn, patindex('%T[0-9][0-9]%', OldColumn) + 1, 2)
where patindex('%T[0-9][0-9]%', OldColumn) <> 0
精彩评论