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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:52:10+00:00 2026-05-23T15:52:10+00:00

I have a table called results and the data looks like: Response_ID order [part

  • 0

I have a table called results and the data looks like:

Response_ID  order    [part label]             [Answer text]     [Answer label]
124587       6        It was not clear         NULL               Yes
124587       6        Did not Understand      Null                Yes
124589       6        Other (Please specify):  Not enough         Yes 
124563       1        NULL                     Satisfied?         Yes
124583       11       Not frequent             NULL               Yes  
125687       2        NULL                     Resolved?          NO

I want Output as:

Response_ID           [Part label]
124587                It was not clear,Did not Understand 
124589                Not enough         
124563                Yes
124583                Not frequent
125687                NO

The logic is whenever Order is 6 or 11 then I need to display the [Part Label] if the [Part Label] has multiple value for one Response_ID then I need to concatenate them but when the value of [Part Label] is Other (Please specify): then I need to use value from Answer Text column and if the order is not in 6,11 then I need to display the value from Answer label

  • 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-23T15:52:10+00:00Added an answer on May 23, 2026 at 3:52 pm

    I had not seen the part about the order. I hope it works now.

    DECLARE @t TABLE (Response_ID INT,[order] INT, [part label] VARCHAR(25), [Answer text] VARCHAR(15), [Answer label] VARCHAR(3))
    
    INSERT @t VALUES (124587,6 , 'It was not clear'       , NULL        , 'Yes')
    INSERT @t VALUES (124587,6 , 'Did not Understand'    , Null        , 'Yes' )
    INSERT @t VALUES (124589,6 , 'Other (Please specify):','Not enough' , 'Yes')
    INSERT @t VALUES (124563,1 , NULL                     ,'Satisfied?' , 'Yes')
    INSERT @t VALUES (124583,11, 'Not frequent'           , NULL        , 'Yes') 
    INSERT @t VALUES (125687,2 , NULL                     ,'Resolved?'  , 'NO' )
    
    SET ARITHABORT ON
    
    ;WITH x AS   ( 
    SELECT CASE WHEN [order] = 11 THEN 6 ELSE [order] END [order], response_id, COALESCE(CASE WHEN [part label] = 'Other (Please specify):' THEN [Answer text] ELSE [part label] end ,[Answer label]) [Part label] 
    FROM @t
    ) 
    SELECT response_id, STUFF(( 
            SELECT ',' + [Part label] 
            FROM x t1 
            WHERE t1.response_id = x.response_id and t1.[order] = x.[order]
            for xml path(''), type 
        ).value('.', 'varchar(max)'), 1, 1, '') [Part label] FROM x
    GROUP BY response_id, [order]
    

    Result:

    response_id Part label
    ----------- -------------------------------------
    124563      Yes
    124583      Not frequent
    124587      It was not clear,Did not Undersstand
    124589      Not enough
    125687      NO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have a table called Results and the data looks like: Response_ID Label 12147
We have a table called table1 ... (c1 int indentity,c2 datetime not null,c3 varchar(50)
Imagine I have the following data in a table called messages: message_id | language_id
Lets say I have a database table called Scrape possibly setup like: UserID (int)
I have a table called myatts : It has about 3,332,834 rows of data.
I have GetConversationPaged sp that selects paged data from table called user_messages_index and includes
I have table called stats . In am inserting yes or no in the
I have a table called OffDays, where weekends and holiday dates are kept. I
I have a Table called Product and I have the Table StorageHistory . Now,
I have a table called ApprovalTasks... Approvals has a status column I also have

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.