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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:29:15+00:00 2026-06-15T13:29:15+00:00

I need my select to have a pattern like this: SELECT ‘<text> ‘ +

  • 0

I need my select to have a pattern like this:

 SELECT '<text> ' + tbl.* + ' </text>' FROM table tbl;

The ideal solution would have all the columns separated by a comma in order to have that output:

SQL result for Table 1 with two columns:

'<text>col1, col2</text>'

SQL result for Table 2 with three columns:

'<text>col1, col2, col3</text>' 

I tried to use the CONCAT(...) function like this:

SELECT CONCAT('<text>', tbl.*, '</text>')
FROM table2 tbl

But I understand it is not so simple because the variable number of columns.

Is there any simple solution to address that problem?

I am using SQL Server 2008 R2.

  • 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-15T13:29:16+00:00Added an answer on June 15, 2026 at 1:29 pm

    Any number of columns for a given tablename;
    If you need column names wrapped with <text>

    DECLARE @s VARCHAR(500)
    
    SELECT @s =  ISNULL(@s+', ','') + c.name   
    FROM  sys.all_columns c join sys.tables  t 
                ON  c.object_id = t.object_id
    WHERE t.name = 'YourTableName'
    
    SELECT '<text>' + @s + '</text>'
    

    SQL Fiddle Example here

    -- RESULTS 
    <text>col1, col2, col3,...</text>
    

    If you need select query result set wrapped with <text> then;

    SELECT @S =  ISNULL( @S+ ')' +'+'',''+ ','') + 'convert(varchar(50), ' + c.name    FROM 
           sys.all_columns c join sys.tables  t 
           ON  c.object_id = t.object_id
    WHERE t.name = 'YourTableName'
    
    
    EXEC( 'SELECT ''<text>''+' + @s + ')+' + '''</text>'' FROM YourTableName')
    

    SQL Fiddle Example here

    --RESULTS
    <text>c1r1,c2r1,c3r1,...</text>
    <text>c1r2,c2r2,c3r2,...</text>
    <text>c1r3,c2r3,c3r3,...</text>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one scenario where I need to select all files having aliencoders.numeric-digits like
I need a PHP regular expression pattern to select separately all lists <ul></ul> from
I have a table with a datetime record. I need to select the record
i have a HTML like this. I need to get the selected value's count
I have a case where I need to select a random item, but I
I have some elements with (.) periods in them and I need to select
I have these elements, and I need to select the li inside the ul
I have a feature matrix implemented with Silverlight's Grid where users need to select
Suppose i have 1kk records in my database. Now i need to select some
I have a method with at least 50 local variables. I need to select

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.