Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use sql to get the numeric part of a string

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge about "how to use sql to obtain the number part of a string". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

The copy code is as follows:

create function dbo.F_Get_No ( @No varchar(100) ) RETURNS bigint AS BEGIN WHILE PATINDEX ('%[^0-9]%',@No)>0 BEGIN SET @No=STUFF(@No,PATINDEX ('%[^0-9]%',@No),1,')--Delete one non-numeric character, loop ends, remaining numeric part END RETURN CONVERT(bigint,@No) END

The PATINDEX function returns the index of the first occurrence of the content in a string. The STUFF function deletes characters of a specified length and inserts another set of characters at a specified starting point. select F_Get_No ('sdsdf 2334sfsd 234') returns '2334234' Note: This method can solve the query of a field in which the number part is a fixed value record, the letter part is a fixed value similar

"How to use sql to get the number part of a string" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report