简体   繁体   中英

SQL SSRS SQL QUERY

I have data in column like PERM12234, PERM7685. It is combination of text and integer. I want only integer part of it.

Example I like to select only 12234 from PERM12234.

Thanks In advance

Use Substring function to get numbers from a string

DECLARE @str VARCHAR(MAX)  = 'abcd123456'

select substring(@str,PATINDEX('%[0-9]%', @str ),len(@str))

使用子字符串功能:仅当您的列值始终从PERM开始时才起作用

select substring(columnname,5,len(columnname)-4)

You can use this code

 DECLARE @str VARCHAR(MAX)  SELECT LEFT(@str, PATINDEX('%[0-9][^0-9]%', @str )) AS Number,
   LTRIM(RIGHT(@str, LEN(@str) - PATINDEX('%[0-9][^0-9]%', @str ))) As Alpha

or

SELECT (@str, 5) AS Number;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM