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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:39+00:00 2026-05-23T13:44:39+00:00

I have the following Query: SELECT CASE WHEN [Question Order] IN ( 6, 11

  • 0

I have the following Query:

SELECT  CASE WHEN [Question Order] IN ( 6, 11 )
             THEN CASE WHEN [Question Part Label] = 'Other (Please specify):'
                       THEN [Answer Text]
                       ELSE [Question Part Label]
                  END
             ELSE 'replace code here'
        END,[Respondent ID]
FROM    Results
WHERE  [Question Order] IN ( 6, 11 ) AND [Answer Label] = 'Yes'

Now I want to replace this code where it says ‘replace code here’

 select         
 stuff((select ','+T2.[Question Part Label]   from Results as T2 
   where T1.[Respondent ID] = T2.[Respondent ID]    for xml path(''), type).value('.', 'varchar(max)'), 1, 1, '') 
   as Label from Results as T1 group by T1.[Respondent ID] 

When I do that I get the following error

Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Sample Data:

Respondent ID  [Question Order]  [Question Part Label]   [Answer Text]   [Answer Label]
124587          6                It was not clear          NULL           Yes
124587          6                Did not Undersstand       NULL           Yes
124589          6                Other (Please specify):   Not enough     Yes
125654          6                Too Fast                  NULL           Yes
124582          11               Not frequent              NULL           Yes

The output Shpuld be:

Respondent ID           [Question Part Label]
124587                  It was not clear,Did not Undersstand
124589                  Not Enough
125654                  Too Fast
124582                  Not frequent

The logic is whenever Question Order is 6 or 11 then I need to dislay the [Question Part Label] if the [Question Part Label] has multiple value for one Respondent_ID then I need to concatenate them but when the value of [Question Part Label] is Other (Please specify): then I need to use value from Answer Text column
an

How can I fix this?

  • 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-23T13:44:40+00:00Added an answer on May 23, 2026 at 1:44 pm
    DECLARE @Results TABLE
    (
        Respondent_ID INT,
        [Question Order] INT,
        [Question Part Label] VARCHAR(40),
        [Answer text] VARCHAR(80),
        [Answer Label] VARCHAR(10)
    );
    
    INSERT @Results
        SELECT       124587, 6, 'It was not clear',        NULL,         'Yes'
        UNION SELECT 124587, 6, 'Did not Undersstand',     NULL,         'Yes'
        UNION SELECT 124589, 6, 'Other (Please specify):', 'Not enough', 'Yes'
        UNION SELECT 124654, 6, 'Too Fast',                NULL,         'Yes'
        UNION SELECT 124582, 11, 'Not frequent',           NULL,         'Yes';
    
    WITH x AS 
    (
        SELECT Respondent_ID 
            FROM @Results 
            WHERE [Question Order] IN (6,11)
            GROUP BY Respondent_ID
    )
    SELECT x.Respondent_ID, Label = STUFF((SELECT ',' + CASE 
        WHEN [Question Part Label] = 'Other (Please specify):' THEN [Answer text] 
        ELSE [Question Part Label] END
        FROM @Results 
        WHERE [Question Order] IN (6,11)
        AND Respondent_ID = x.Respondent_ID
        FOR XML PATH(''), TYPE).value(N'./text()[1]', N'varchar(max)'), 1, 1, '')
        FROM x;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: select column_name, count(column_name) from table group by column_name having
I have the following query: SELECT c.* FROM companies AS c JOIN users AS
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following (shortened query): SELECT `Statistics`.`StatisticID`, COUNT(DISTINCT `Flags`.`FlagType`) AS `FlagCount` FROM `Statistics`
I have a select query that currently produces the following results: Description Code Price
I have the following Java 6 code: Query q = em.createNativeQuery( select T.* +
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
HI, Using SQL server 2005 I have the following query: SELECT contact_id ,YEAR(date_created) AS
I have the following SQL query SELECT tbl_product.prod_id, ISNULL (prod_code, '') AS prod_code, ISNULL

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.