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

  • Home
  • SEARCH
  • 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 8577721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:13:24+00:00 2026-06-11T20:13:24+00:00

I have two columns ( A, B ) like this…. A B 12_18_19 20

  • 0

I have two columns (A, B) like this….

A           B
12_18_19    20

I want a 3rd column (C) added within same SELECT statement like this…

C
12_18_20_19

in other words, my column A is delimited by “_”, so the second last index of column A should be column B.

If possible I would do do all this within same SELECT statement like this…

A         B    C
12_18_19  20   12_18_20_19
  • 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-11T20:13:25+00:00Added an answer on June 11, 2026 at 8:13 pm

    How about:

    SELECT 
        A, B, 
        C = SUBSTRING(A, 1, LEN(A) - CHARINDEX('_', REVERSE(A))) + 
            '_' + B + 
            SUBSTRING(A, LEN(A) + 1 - CHARINDEX('_', REVERSE(A)), 999)
    FROM 
        dbo.YourTable 
    

    It’s a bit involved, mostly also because there is no LASTCHARINDEX() function in T-SQL.

    The first expression parses the A column up to the last _ separator characters and takes everything before that. Then it appends a _ and column B, and then grabs everything after that last _ separator from A and appends that.

    And as Andriy M rightfully mentioned in his comment : if A or B are NULL, then the whole result is NULL, too. If the columns are empty strings, or if A doesn’t contain any _ characters, you’ll might get errors (since the parsing will fail) or unexpected, messy results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two EXT JS check columns like this: var maleColumn = new Ext.grid.CheckColumn({
I have two columns like this. (TC_NO is 11 character, VER_NO is 10 character)
In my MySQL database I have two columns setup like this (for example): series_id
I have two columns. People have to select elements from the first column and
I have two columns in Excel, like this: A B 0.5 0.4 0.6 0.59
I have SP that selects data from a table with two columns like this
I have two columns A and B, and would like to get a list
I have a two column layout: http://jsfiddle.net/KqQ42/1/ Now I would like that the left
I have a website with a two column layout, like there are dozens I
I have two files. file1 has the data like belowing containing only one column.

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.