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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:21:41+00:00 2026-06-16T18:21:41+00:00

Microsoft SQL Server 2008 I have two tables. One has a column in it

  • 0

Microsoft SQL Server 2008

I have two tables. One has a column in it with data that is _ delimited

example:

Y_21_CA
<BR>
such that:
Yes/No_Age_State

I need to parse the data in this column out and insert it into another table that has individual columns for each value. Let’s say Table A contains one column like the example above but Table B contains three columns, YesOrNo, Age, usState.

What’s the easiest way to do this? I’ve tried doing something like:

UPDATE TableA
SET YesOrNo = SUBSTRING (TableB.Column1, 1, 1)

but SUBSTRING only takes an expression. I really just need some guidance here, I’ve been banging my head against the wall trying to figure this out since I’m not much of a SQL guru. I can figure out the syntax no problem but maybe I’m not aware of some methods that exist. Thanks

  • 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-16T18:21:43+00:00Added an answer on June 16, 2026 at 6:21 pm

    A generic solution, using Charindex of ‘_’ without hardcoding it

    declare @s varchar(10) = 'Y_21_CA'   
    
    SELECT LEFT(@s, CHARINDEX('_',@s,1)-1) YN, 
           SUBSTRING(@s, CHARINDEX('_',@s,1)+1,  
                     CHARINDEX('_',@s,CHARINDEX('_',@s,1)) ) Age,
           RIGHT(@s, CHARINDEX('_',reverse(@s),1)-1) State 
    
    --Results
    Y   21   CA
    

    In case you expect to use this logic often in other queries, you could make the SELECT statement an inline TVF. Then you would be able to use it with your update like this:

    UPDATE b
    SET YesOrNo = x.YN,
        Age = x.Age,
        State = x.State
    FROM TableB b
    INNER JOIN TableA a ON b.ID = a.ID
    CROSS APPLY ThreeColumnSplit(a.S) x;
    

    Here’s a “live” demo at SQL Fiddle. (Please never mind its using the SQL Server 2012 engine. That’s only because the Fiddle’s 2008 instance appears to be down at the moment and can’t be used. There’s nothing SQL Server 2012-specific in the script.)

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

Sidebar

Related Questions

I have a Microsoft SQL Server 2008 query that returns data from three tables
I have data in Microsoft SQL Server 2008 that I need to SUM. The
I have two lookup/reference tables (Subscribed and Unsubscribed) in my Microsoft SQL Server 2008
Using Microsoft SQL server 2008 I have a query that is in need of
I'm creating a constraint on a (Microsoft) Sql Server 2008 table. I have two
I have a 2nd computer that I've installed Microsoft SQL Server 2008 Express on.
I have two tables with the exact same schema in SQL Server 2008 Standard
I am using Microsoft SQL Server 2008 Report Builder . I have designed some
I have Microsoft SQL Server Express Edition with Advanced Services for 2008. I only
I'm using SQL Server 2008 R2 and Microsoft Excel. I have the server set

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.