i in solving following issue using patindex function cannot retrieve or extract single numeric value example in the values below retrieve value 2, in result set value 22 appears or omitted.
i need extract single numeric value 2 , not 22
"2 8 7"
"2 8"
"2"
"22"
"3 2 8"
i have tried following patindex('%[2]% [^0-9] [^1] [^3] [^4] [^5] [^6] [^7] [^8] [^9]' ,replace(replace(marketing_special_attributes, '"',''),'^',' ')) col3,
patindex('[2]' ,replace(replace(marketing_special_attributes, '"',''),'^',' ')) col4,
patindex('%[2][^0-9]%',replace(marketing_special_attributes,'^',' ')),
all appreciated
you can identify single digit with:
where ' ' + col + ' ' '% [0-9] %' hence, can similar find pattern:
select substr(col, patindex('% [0-9] %', ' ' + col + ' '), 1) (because of spaces, patindex() value off-by-1 relative original string.)
however, seem storing lists of numbers string -- , bad idea. lists should stored in tables, 1 row per entity , entity item.
Comments
Post a Comment