Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:46:07+00:00 2026-06-15T01:46:07+00:00

I have a table like this Declare @Temp Table(Data VarChar(20)) Insert Into @Temp Values(‘F_200_100_’)

  • 0

I have a table like this

Declare @Temp Table(Data VarChar(20))

Insert Into @Temp Values('F_200_100_')
Insert Into @Temp Values('F_50_')
Insert Into @Temp Values('F_30_')
Insert Into @Temp Values('F_50_10')
Insert Into @Temp Values('F_100_')
Insert Into @Temp Values('F_20_')

I want my output to be distinct values of the numbers extracted from data column

20
30
50
100
200

I have tried using patindex but I am looking for ideas
tried this

select
Left(
SubString(Data, PatIndex('%[0-9]%', Data), 8000), 
PatIndex('%[^0-9]%', SubString(Data, PatIndex('%[0-9]%', Data), 8000) + 'X')-1
)
from @temp

Reference
http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/extracting-numbers-with-sql-server

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:46:08+00:00Added an answer on June 15, 2026 at 1:46 am

    try this:

    DECLARE @YourTable table (RowID int, Layout varchar(200))
    INSERT INTO @YourTable 
    select ROW_NUMBER() over (order by (select 0)) as rn,replace(RIGHT(data,len(data)-CHARINDEX('_',data,1)),'_',',') from temptab
    
    ;WITH SplitSting AS
    (
        SELECT
            RowID,LEFT(Layout,CHARINDEX(',',Layout)-1) AS Part
                ,RIGHT(Layout,LEN(Layout)-CHARINDEX(',',Layout)) AS Remainder
            FROM @YourTable
            WHERE Layout IS NOT NULL AND CHARINDEX(',',Layout)>0
        UNION ALL
        SELECT
            RowID,LEFT(Remainder,CHARINDEX(',',Remainder)-1)
                ,RIGHT(Remainder,LEN(Remainder)-CHARINDEX(',',Remainder))
            FROM SplitSting
            WHERE Remainder IS NOT NULL AND CHARINDEX(',',Remainder)>0
        UNION ALL
        SELECT
            RowID,Remainder,null
            FROM SplitSting
            WHERE Remainder IS NOT NULL AND CHARINDEX(',',Remainder)=0
    )
    SELECT distinct cast(part as int) FROM SplitSting where len(part) > 0  order by cast(part as int)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two temp tables like this: declare @Tbl_A table ( Id int )
I have table values in this format sam jack sam john Declare @name varchar(max)
i have simple data coming in like this: declare @string varchar(500) = val1|val2|val3 how
I have a table like this: CREATE TABLE book_info ( book_id VARCHAR(32) not null,
I have a test table like this CREATE TABLE #temp ( rid INT IDENTITY
I have my table schema and data something like this CompanyCategoryId SubCategoryId CategoryId CompanyId
Dear Stackoverflow members I have a recursive CTE query like this: DECLARE @Level TABLE
I have this table declare @temp_xml table ( question_id int, question_xml xml ) insert
I have table like this : ID Name_1 Name_2 Name_3 1 Egon Spengler Ives
I have a table like this ID Name IsDeleted 1 Yogesh Null 2 Goldy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.