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 7899455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:42:25+00:00 2026-06-03T08:42:25+00:00

I have the following string. Input ————– 2030031469-NAI To get the numeric part, I

  • 0

I have the following string.

Input
--------------
2030031469-NAI 

To get the numeric part, I am using the following script

declare @str varchar(50)= '2030031469-NAI'

Select 
    @str
    ,SUBSTRING(@str, 1,  NULLIF(CHARINDEX('-', @str) - 1, -1))
        ,Left(@str,PATINDEX('%-%',@str)-1)

to get the following output

Output: 
----------
2030031469

Is there any other easy/elegant way of doing the same?

  • 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-03T08:42:27+00:00Added an answer on June 3, 2026 at 8:42 am
    select left(@str, patindex('%[^0-9]%', @str+'.') - 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have the following date as String format. Input 2010-04-20 05:34:58.0 Output I
A have the following input string: string input = Ta005000000000000000000Tb001700000000000000000Sa005000000000000000000 + Sb002500000000000000000F 00000000000000000I 00000000000000000N
I have following problem: Input String 1 : A[SPACE]B[SPACE]C[SPACE][SPACE]D[SPACE][SPACE]E Input String 2 : 1-
I have an input string in the following format String input = 00IG356001110002005064007000000; Characters
I have the following JSON string coming from external input source: {value: "82363549923gnyh49c9djl239pjm01223", id:
I have the following regular expression validator to detect whether an input string contains
I have the following function DateTime fromDateParam = DateTime.ParseExact(Convert.ToString(DateTime.MinValue),dd.MM.yyyy HH:mm:ss,null); It says input string
I have the following code: string input = ç; string normalized = input.Normalize(NormalizationForm.FormD); char[]
I have an input string that's generated as in following example: string.Format(Document {0}, was
I have the following simple script that accepts text as input and writes it

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.