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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:55:50+00:00 2026-06-15T00:55:50+00:00

I have the following sample table structures for a parent / child relationship. parent

  • 0

I have the following sample table structures for a parent / child relationship.

parent table

id    LongText
--------------
10    
20    

child table

id    char     value
--------------------
10    COLOR    RED
10    HEIGHT   1FT
20    COLOR    BLUE
20    WIDTH    2FT

I have a requirement that specifies that certain fields from the child table rows need to be concatenated together and placed in the parent table. I would like to complete this in a single SQL query if possible. The update statement that I have written is as follows.

UPDATE
  parent
SET
  LongText = COALESCE(LongText, N'')
              + child.char + N': ' + child.val + ','
FROM
  parent INNER JOIN child
    ON
      parent.id = child.id

But I only get the following results.

id    LongText
------------------
10    COLOR: RED,
20    COLOR: BLUE,

I would expect (or I should say I WANT) to get this.

id    LongText
------------------
10    COLOR: RED,HEIGHT: 1FT
20    COLOR: BLUE,WIDTH: 2FT

Is this possible? Any suggestions as to how I can do this? Any help is appreciated!

Here is a SQLfiddle for reference.

  • 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-15T00:55:52+00:00Added an answer on June 15, 2026 at 12:55 am
    update parent
    set longtext =
        stuff((
        select ',' + c.char + ': ' + c.val
        from child c
        where c.uid = parent.uid
        for xml path(''), type).value('.','nvarchar(max)'),1,1,'');
    

    I have updated your SQLFiddle with the solution.

    1. STUFF() function to remove the leading ',' (comma) from the first characteristic.

    2. FOR XML to create an XML document from a query result. This is a well known trick with SQL Server – because the column is not named, there is no element produced and only the raw text (of each row) is output, mashed together into a single row.

    Very few articles on the internet attempt to explain it in detail, since the code is pretty much left as an explanation in and of itself.

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

Sidebar

Related Questions

I have the following sample of data to insert into tables(from parent to child,
I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
a simple question for all you SQL gurus: I have the following table structures
I have a table with the following structure - steamid, itemid, eventid, value ,
I have a table with the following structure key1 varchar(255) key2 varchar(255) value decimal(6,2)
1I have the following two tables (sample data) and need to be able to
I have the following task: there are a simple table from mysql database: <html>
I have a very simple table called Member , which consists of the following:
I have the following PHP code doing a very simple select into a table.

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.