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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:57:52+00:00 2026-06-10T17:57:52+00:00

All, this is something I have not had to do before and I cannot

  • 0

All, this is something I have not had to do before and I cannot locate a simalar question for some reason. I wish to return the NVARCHAR @columnHeaders to a String in C#. The SQL query that will build the string I want is this

DECLARE @columnHeaders NVARCHAR(MAX); 
SELECT @columnHeaders = 
    COALESCE (@columnHeaders + ',[' + Field + ']', '[' + Field + ']') 
FROM SomeTable;

However, how do I then pull the variable @columnHeaders back into C#? Note, I could use a function etc., but I do not want to use Stored Procedures, Views or Functions unless absolutely neccessary…

I can select the the columnn headers in to a DataTable using

DECLARE @columnHeaders NVARCHAR(MAX); 
SELECT COALESCE (@columnHeaders + ',[' + Field + ']', '[' + Field + ']') 
FROM SomeTable;

and manipulate in C#, but it would be nice to return the string direct from SQL.

Thanks for your time.

  • 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-10T17:57:54+00:00Added an answer on June 10, 2026 at 5:57 pm

    If you don’t want to use stored procedures, this will probably work.

    DECLARE @columnHeaders NVARCHAR(MAX);  
        SELECT @columnHeaders =  
        COALESCE (@columnHeaders + ',[' + Field + ']', '[' + Field + ']')  
        FROM SomeTable; 
        select @columnHeaders
    

    and use ExecuteScalar() to get the results.

    However, I would personally recommend a stored procedure as being far neater, in that it keeps the SQL in the SQL Server.

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

Sidebar

Related Questions

Let's say I started a thread and I have something like this: ...//initiate all
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
This question HAS had to be asked before, so it kills me to ask
this seems a common problem, except I have had no trouble with this before
Here's a real life example I had experienced before, and this is something that
First of all, I love ASP.NET MVC. This question is not a criticism of
I have something very similar to this example: https://developers.google.com/maps/documentation/javascript/examples/directions-simple All I am trying to
I have this string: var someString = 23/03/2012; and want to replace all the
This Code: Something = new Guid() is returning: 00000000-0000-0000-0000-000000000000 all the time and I
Does something like this make any sense at all in Java? class A<T extends

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.