TSQL - Regular Expression Example : Tsql Filter data based on Certain Pattern
i will let you how to use Regular Expression in Tsql using one example /
we need to filter the data of varchar column , value should be like DSx_HD_WSxx example DS1_HD_WS01_blablabla .
for this we can achieve by using 'DS__HD_WS__%' but the problem is, we can also get DS10 or DS1000 .
In this case what pattern we need to use to accept any number after DS then remaining as per previous patern.
we can achieve solution with the fallowing expression
'DS%[_]HD_WS%[_]%'
we need to filter the data of varchar column , value should be like DSx_HD_WSxx example DS1_HD_WS01_blablabla .
for this we can achieve by using 'DS__HD_WS__%' but the problem is, we can also get DS10 or DS1000 .
In this case what pattern we need to use to accept any number after DS then remaining as per previous patern.
we can achieve solution with the fallowing expression
'DS%[_]HD_WS%[_]%'
For single character we need to use underscore _ and for many chacters we need to use %
Comments
Post a Comment