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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:07:48+00:00 2026-05-23T05:07:48+00:00

I’m trying to extract some data from a third party system which uses an

  • 0

I’m trying to extract some data from a third party system which uses an SQL Server database. The DB structure looks something like this:

Order

OrderID   OrderNumber
   1         OX101 
   2         OX102

OrderItem

OrderItemID  OrderID   OptionCodes
     1          1      12,14,15
     2          1      14
     3          2      15

Option

OptionID   Description
    12      Batteries
    14      Gift wrap
    15      Case
[etc.]

What I want is one row per order item that includes a concatenated field with each option description. So something like this:

OrderItemID   OrderNumber   Options
    1            OX101      Batteries\nGift Wrap\nCase
    2            OX101      Gift Wrap
    3            OX102      Case

Of course this is complicated by the fact that the options are a comma separated string field instead of a proper lookup table. So I need to split this up by comma in order to join in the options table, and then concat the result back into one field.

At first I tried creating a function which splits out the option data by comma and returns this as a table. Although I was able to join the result of this function with the options table, I wasn’t able to pass the OptionCodes column to the function in the join, as it only seemed to work with declared variables or hard-coded values.

Can someone point me in the right direction?

  • 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-23T05:07:48+00:00Added an answer on May 23, 2026 at 5:07 am

    I would use a splitting function (here’s an example) to get individual values and keep them in a CTE. Then you can join the CTE to your table called “Option”.

    SELECT * INTO #Order
    FROM (
      SELECT 1 OrderID, 'OX101' OrderNumber UNION SELECT 2, 'OX102'
    ) X;
    
    SELECT * INTO #OrderItem
    FROM (
      SELECT 1 OrderItemID, 1 OrderID, '12,14,15' OptionCodes
      UNION
      SELECT 2, 1, '14'
      UNION
      SELECT 3, 2, '15'
    ) X;
    
    SELECT * INTO #Option
    FROM (
      SELECT 12 OptionID, 'Batteries' Description
      UNION
      SELECT 14, 'Gift Wrap'
      UNION
      SELECT 15, 'Case'
    ) X;
    
    WITH N AS (
      SELECT I.OrderID, I.OrderItemID, X.items OptionCode
      FROM #OrderItem I CROSS APPLY dbo.Split(OptionCodes, ',') X
    )
    SELECT Q.OrderItemID, Q.OrderNumber,
           CONVERT(NVarChar(1000), (
             SELECT T.Description + ','
             FROM N INNER JOIN #Option T ON N.OptionCode = T.OptionID
             WHERE N.OrderItemID = Q.OrderItemID
             FOR XML PATH(''))
           ) Options
    FROM (
      SELECT N.OrderItemID, O.OrderNumber
      FROM #Order O INNER JOIN N ON O.OrderID = N.OrderID
      GROUP BY N.OrderItemID, O.OrderNumber) Q
    
    DROP TABLE #Order;
    DROP TABLE #OrderItem;
    DROP TABLE #Option;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from

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.