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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:48:06+00:00 2026-05-24T22:48:06+00:00

I’m doing some reporting against a silly database and I have to do SELECT

  • 0

I’m doing some reporting against a silly database and I have to do

SELECT [DESC] as 'Description' 
FROM dbo.tbl_custom_code_10 a
INNER JOIN dbo.Respondent b ON CHARINDEX(',' + a.code + ',', ',' + b.CC10) > 0 
WHERE recordid = 116

Which Returns Multiple Rows

 Palm
 Compaq
 Blackberry

Edit *
Schema is

Respondent Table (At a Glance) ...

*recordid   lname   fname   address CC10     CC11     CC12     CC13*
116         Smith   John    Street  1,4,5,   1,3,4,   1,2,3,   NULL

Tbl_Custom_Code10

*code   desc*
0       None
1       Palm
10      Samsung
11      Treo
12      HTC
13      Nokia
14      LG
15      HP
16      Dash

Result set will always be 1 row, so John Smith: | 646-465-4566 | Has a Blackberry, Palm, Compaq | Likes: Walks on the beach, Rainbows, Saxophone

However I need to be able to use this within another query … like

Select b.Name, c.Number, d.MulitLineCrap FROM Tables 

How can I go about this, Thanks in advance …

BTW I could also do it in LINQ if any body had any ideas …

  • 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-24T22:48:08+00:00Added an answer on May 24, 2026 at 10:48 pm

    Here is one way to make a comma-separated list based on a query (just replace the query inside the first WITH block). Now, how that joins up with your query against b and c, I have no idea. You’ll need to supply a more complete question – including specifics on how many rows come back from the second query and whether "MultilineCrap" is the same for each of those rows or if it depends on data in b/c.

    ;WITH x([DESC]) AS 
    (
      SELECT d FROM (VALUES('Palm'),('Compaq'),('Blackberry')) AS x(d)
    )
    SELECT STUFF((SELECT ',' + [DESC]
      FROM x 
      FOR XML PATH(''), TYPE).value(N'./text()[1]', N'varchar(max)'),1,1,'');
    

    EDIT

    Given the new requirements, perhaps this is the best way:

    CREATE FUNCTION dbo.GetMultiLineCrap
    (
        @s VARCHAR(MAX)
    ) 
    RETURNS VARCHAR(MAX)
    AS
    BEGIN
        DECLARE @x VARCHAR(MAX) = '';
        
        SELECT @x += ',' + [desc]
            FROM dbo.tbl_custom_code_10
            WHERE ',' + @s LIKE '%,' + RTRIM(code) + ',%';
        
        RETURN (SELECT STUFF(@x, 1, 1, ''));
    END
    GO
    
    SELECT r.LName, r.FName, MultilineCrap = dbo.GetMultiLineCrap(r.CC10)
        FROM dbo.Respondent AS r
        WHERE recordid = 116;
    

    Please use aliases that make a little bit of sense, instead of just serially applying a, b, ,c, etc. Your queries will be easier to read, I promise.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
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 have a reasonable size flat file database of text documents mostly saved in
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.