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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:05:37+00:00 2026-05-13T19:05:37+00:00

I have a column with data in a special format. Example: L100000 L50 L5

  • 0

I have a column with data in a special “format”. Example:

L100000
L50
L5
S10
S15L10
S20
S90
S10
S10L5
S10L40
S10L5

The value consists of an “S” and/or an “L”, each with a number following the letter.
I need to write a query, which will return two columns, “S” and “L”, which will have only the coresponding numeric value following the letter.
The above example should look like this:

S         L  
========  ==========
0         100000
0         50
0         5
10        0
15        10
20        0
90        0
10        0
10        5
10        40
10        5

If no “S” or “L” is found, the default value is zero.

  • 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-05-13T19:05:38+00:00Added an answer on May 13, 2026 at 7:05 pm

    try this:

    DECLARE @YourTable table (RowValue varchar(30))
    
    INSERT INTO @YourTable VALUES ('L100000')
    INSERT INTO @YourTable VALUES ('L50')
    INSERT INTO @YourTable VALUES ('L5')
    INSERT INTO @YourTable VALUES ('S10')
    INSERT INTO @YourTable VALUES ('S15L10')
    INSERT INTO @YourTable VALUES ('S20')
    INSERT INTO @YourTable VALUES ('S90')
    INSERT INTO @YourTable VALUES ('S10')
    INSERT INTO @YourTable VALUES ('S10L5')
    INSERT INTO @YourTable VALUES ('S10L40')
    INSERT INTO @YourTable VALUES ('S10L5')
    
    SELECT
        CASE
            WHEN LocationS>0 AND LocationL=0 THEN RIGHT(RowValue,Length-1)
            WHEN LocationS>0 THEN SUBSTRING(RowValue,2,LocationL-2)
            ELSE NULL
        END AS S
        ,CASE
             WHEN LocationS=0 AND LocationL>0 THEN RIGHT(RowValue,Length-1)
             WHEN LocationS>0 AND LocationL>0 THEN RIGHT(RowValue,Length-LocationL)
             ELSE NULL
         END AS L
        ,RowValue
        FROM (SELECT
                  RowValue
                      ,CHARINDEX('S',RowValue) AS LocationS
                      ,CHARINDEX('L',RowValue) AS LocationL
                      ,LEN(RowValue) AS Length
                  FROM @YourTable
             ) dt
    

    OUTPUT

    S                              L                              RowValue
    ------------------------------ ------------------------------ --------------
    NULL                           100000                         L100000
    NULL                           50                             L50
    NULL                           5                              L5
    10                             NULL                           S10
    15                             10                             S15L10
    20                             NULL                           S20
    90                             NULL                           S90
    10                             NULL                           S10
    10                             5                              S10L5
    10                             40                             S10L40
    10                             5                              S10L5
    
    (11 row(s) affected)
    

    if you have loads of data give this a try, it may be faster (has same output, basically removed the derived table and made everything use inline functions):

    SELECT
        CASE
            WHEN CHARINDEX('S',RowValue)>0 AND CHARINDEX('L',RowValue)=0 THEN RIGHT(RowValue,LEN(RowValue)-1)
            WHEN CHARINDEX('S',RowValue)>0 THEN SUBSTRING(RowValue,2,CHARINDEX('L',RowValue)-2)
            ELSE NULL
        END AS S
        ,CASE
             WHEN CHARINDEX('S',RowValue)=0 AND CHARINDEX('L',RowValue)>0 THEN RIGHT(RowValue,LEN(RowValue)-1)
             WHEN CHARINDEX('S',RowValue)>0 AND CHARINDEX('L',RowValue)>0 THEN RIGHT(RowValue,LEN(RowValue)-CHARINDEX('L',RowValue))
             ELSE NULL
         END AS L
        ,RowValue
        FROM @YourTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date column in a data frame in chr format as follows:
I have a column of name, varchar(200). In this column data can be filled
If I have a table column with data and create an index on this
I have a User_Id column with data DOMAIN\USERID I need it to be DOMAIN\userid
I have a column that has the following data: PersonId=315618 LetterId=43 MailingGroupId=1 EntityId=551723 trackedObjectId=9538
I have a varchar column that has data like this top<somenumber> so the word
I have an xml column which contain data like this: <AuthorList CompleteYN=Y> <Author ValidYN=Y>
I currently have this code which stores XML into an XML-type column called data,
In Oracle, I have a table with a column of data type NUMBER. I
I have a three column workbook with the following data: Col A: Names Col

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.