| |

VerySource

 Forgot password?
 Register
Search
View: 720|Reply: 5

See if SQL doesn't have such a feature?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-29 17:00:01
| Show all posts |Read mode
I will now process the variables passed in. The variables passed in are: string + number
But I want to take out the numbers, but the string digits are not fixed. Is there such a function in SQL that only takes numbers, for example, pass the parameter "AAA12" and only get 12? fixed
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-3-3 03:30:01
| Show all posts
If there are no numbers in the string, it can be done
Can only write by myself, there is no ready-made
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-3-3 17:15:01
| Show all posts
declare @str varchar (100)
set @ str = 'AAA12'
select right (@str, len (@str) -patindex ('% [0-9]%', @str) +1)
--result
12
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-3-3 22:45:02
| Show all posts
declare @str varchar (100)
set @ str = 'AA12'
select stuff (@str, 1, patindex ('% [0-9]%', @str) -1, '')
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-3-4 10:45:01
| Show all posts
declare @SQL_ALL CHAR (255)
declare @SQL_CHAR CHAR (255)
declare @SQL_INT CHAR (255)
declare @SQL_LEN INT
declare @INT_LEN INT

select @ SQL_ALL = 'AA121334A16552'
SELECT @ SQL_LEN = len (@SQL_ALL)
select @ INT_LEN = 1
while SUBSTRING (@ SQL_ALL, @ SQL_LEN- @ INT_LEN, 1) BETWEEN '1' AND '9'
    SELECT @ INT_LEN = @ INT_LEN + 1

SELECT RIGHT (RTRIM (@SQL_ALL), @ INT_LEN)

--------------
16552
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-3-4 15:00:02
| Show all posts
1. There are no numbers in the middle of the string. It is relatively simple to follow thefanfan1980method.
2. If there may be digits in the middle of the string, judge from the right
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list