Basically I just need to get a 5 digits number that is separated by a space. The 5 digits number can be anywhere in the varchar.
Example: I have a varchar column with this various data in SQL 2008 table
travel visa 34322 LLL001
Coffee 34332 Jakarta
FDR001 34312 Taxi cost cash
taxi cash 34321
34556 eating dinner with customer
eating dinner 34256 with customer
visa cost 34221 REF773716637366
the 5 digits number can be anywhere separated by a space what is best to extract this?
34322
34332
34312
34556
34256
34221
Thanks
Row like this should return blank
Visa refNbr 778738878
Tried the following with no luck yet
SELECT pjtran.tr_comment
,substring(pjtran.tr_comment,PATINDEX('%[0-9]%',pjtran.tr_comment),5)
,Left(SubString(pjtran.tr_comment, PatIndex('%[0-9.-]%', pjtran.tr_comment), 50),PatIndex('%[^0-9.-]%', SubString(pjtran.tr_comment, PatIndex('%[0-9.-]%', pjtran.tr_comment), 50) + 'X')-1)
,len(pjtran.tr_comment)-len(replace(pjtran.tr_comment,' ',''))
I think I need to use a combination of counting the number of space in the varchar. and the above. but I am not sure how to do it