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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:25:19+00:00 2026-06-14T13:25:19+00:00

i need to collect all return data into a variable using comma separated. let

  • 0

i need to collect all return data into a variable using comma separated.

let say i have a select command like: select * from #temptable.
it’s return:

Field1|Field2
-------------
Value1|Value2

Expected Result: @testvariable hold the value: ‘Value1′,’Value2’

On this table their may have 2 columns and i need to store all the return result into a single variable. We can easily collect a single value like: select @var=column1 from #temptable. But i need to store all.Here the problem is, the number of column can be vary. Mean, number of column and name of column generate from another query.So, i can’t mention the field name.I need a dynamic way to do it. on this table only one row will be return. Thanks in advance.

  • 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-14T13:25:20+00:00Added an answer on June 14, 2026 at 1:25 pm

    You can do this without dynamic SQL using XML

    DECLARE @xml XML = (SELECT * FROM #temptable FOR XML PATH(''))
    
    SELECT stuff((SELECT ',' + node.value('.', 'varchar(100)')
                  FROM   @xml.nodes('/*') AS T(node)
                  FOR XML PATH(''), type).value('.','varchar(max)')
                  , 1, 1, ''); 
    

    This can probably be simplified by someone more adept at XML querying than me.

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

Sidebar

Related Questions

I need to use PerfMon to collect data from several machines, and I need
I need to collect usage information on my on-demand application. This should include things
i need to write a program in c# to collect information about processes running
Need some regular expressions help. So far I have my code working to allow
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need help with a query that I wrote: I have three tables Company id
I have the following query which returns the salary of all employees. This work
I have this Core Data Model Hierarchy, with the respective relationships to each other:
The following query returns data right away: SELECT time, value from data order by
I'd like to implement validation for a sequence of operations that all return Either[Error,Item]

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.