Hello,
I am trying to update a column in a table with an 8 digit string.
The 8 digit number is obtained from another column which is a comments
field.
e.g.
Comments Field :
1) RD-V0216970 RQST NON SMKING KING Unknown # : 22338921
2) Received verbal authorization Authorization # 040345
3) international plaza, singapore # 96722540
The code that I am using is
UPDATE U SET U.NUM =
CASE
WHEN U.BOOKED_COMMEN TS_TXT LIKE
('%[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]%')
THEN
SUBSTRING(U.BOO KED_COMMENTS_TX T,
PATINDEX('%[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]%',
U.BOOKED_COMMEN TS_TXT), 8)
ELSE NULL
END
FROM UNKNOWN1_RESERV ATIONS U
Here's what my result set looks like
1)V0216970
2)040345
3)96722540
But this is how I want my result set to look like
1)22338921
2)null
3)96722540
What I need is a way to restrict the search criteria to exactly 8
numeric digits. Any suggestions will be helpful.
Thanks in advance
I am trying to update a column in a table with an 8 digit string.
The 8 digit number is obtained from another column which is a comments
field.
e.g.
Comments Field :
1) RD-V0216970 RQST NON SMKING KING Unknown # : 22338921
2) Received verbal authorization Authorization # 040345
3) international plaza, singapore # 96722540
The code that I am using is
UPDATE U SET U.NUM =
CASE
WHEN U.BOOKED_COMMEN TS_TXT LIKE
('%[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]%')
THEN
SUBSTRING(U.BOO KED_COMMENTS_TX T,
PATINDEX('%[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]%',
U.BOOKED_COMMEN TS_TXT), 8)
ELSE NULL
END
FROM UNKNOWN1_RESERV ATIONS U
Here's what my result set looks like
1)V0216970
2)040345
3)96722540
But this is how I want my result set to look like
1)22338921
2)null
3)96722540
What I need is a way to restrict the search criteria to exactly 8
numeric digits. Any suggestions will be helpful.
Thanks in advance
Comment