question

sakath2009 avatar image
sakath2009 asked

Retrive 5 digit number starting with 2 in a varchar string

Hi Team, My requirement is to retrive a 5 digit number starting with 2 in a varchar string. Ex: my birthday is on Sep 20, 20117 and my friends birthday is on Aug 20, 2016. Like the above i have a huge database, from which i need to retrive the rows having similar errors. This is one string out of this i need to identify the row having the number 20117.
string
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sajikumar.vk avatar image
sajikumar.vk answered
select * from tableName where charindex('20117',column_name) > 0
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

the five digit number can be of any combination, then the above will not be useful.
0 Likes 0 ·
ThomasRushton avatar image
ThomasRushton answered
Wildcard searches in WHERE clauses - https://docs.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql select * from tablename where columnname like '%2[0-9][0-9][0-9][0-9]%' something like that should do the job, anyway.
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.