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

  • Home
  • SEARCH
  • 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 558627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:09:08+00:00 2026-05-13T12:09:08+00:00

Is there a valid way in SQL Server 2005 to read a row of

  • 0

Is there a valid way in SQL Server 2005 to read a row of data into a string?

For example if my table looked like the following:

ID | First Name | Last Name | Color
-----------------------------------
 1 | Timmy      | Jones     | pink
 2 | Martha     | Fisher    | green

That I could get back as a result:

'1 Timmy Jones pink'
'2 Martha Fisher green'

Preferably I could get back with the column name appended such as:

'ID: 1, First Name: Timmy, Last Name: Jones, Color: pink'
'ID: 2, First Name: Martha, Last Name: Fisher, Color: green'

Update:

I’m looking for a dynamic solution so I guess querying against INFORMATION_SCHEMA would be more appropriate.

This actually helps a bit because I’m looking to set it off from an update trigger, so I’ll have one row at a time and I can query against the INFORMATION_SCHEMA for the main table checking datatypes to eliminate text, ntext and image that the generated tables, ‘inserted’ and ‘deleted’ choke on.

Solution: (updated: had to add some more code to return the one value)

-- passed in table name & schema
DECLARE @table_name nvarchar(100)
DECLARE @schema_name nvarchar(100)

-- set initial value
SET @table_name = 'my_table'
SET @schema_name = 'dbo'

-- Variable to hold query
DECLARE @sql nvarchar(MAX)
SET @sql = 'SELECT @row_stringOUT = '

-- Query columns meeting criteria and build query
SELECT
    -- Query as one string
    @sql = (@sql + '  ''  ' + COLUMN_NAME + ': '' + CASE WHEN ' + COLUMN_NAME + ' IS NULL THEN '''' WHEN ISDATE(' + COLUMN_NAME + ') = 1 THEN CONVERT(nvarchar(100), ' + COLUMN_NAME + ', 120) ELSE CAST(' + COLUMN_NAME + ' AS nvarchar(100)) END + ')
FROM 
    INFORMATION_SCHEMA.COLUMNS
WHERE 
    table_schema = @schema_name
    AND
    table_name = @table_name
    AND
    -- Filter out unuseable data types
    data_type NOT IN ('text', 'ntext', 'image')

-- Trim extra character before FROM statement then add FROM statement
SELECT @sql = LEFT(@sql, LEN(@sql) - 1) + ' FROM ' + @table_name;

-- Execute Query
DECLARE @params nvarchar(MAX)
SET @params = N'@row_stringOUT ntext OUTPUT';

DECLARE @ret_value nvarchar(MAX)

EXEC sp_executesql
    @sql
    , @params
    , @row_stringOUT = @ret_value OUTPUT

SELECT @ret_value
  • 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-13T12:09:08+00:00Added an answer on May 13, 2026 at 12:09 pm

    you can just concat the columns. if you want to get column names to you’ll have to use some mix of dynamic sql, INFORMATION_SCHEMA views and querying…

    SELECT  cast(ID as varchar(10)) + ' ' + [First Name] + ' ' + [Last Name] + ' ' + Color 
    FROM    MyTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 298k
  • Answers 298k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thanks lucentmind and BalusC foryour repliees the solution was this:… May 13, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer Woody Peterson found the problem here: http://groups.google.com/group/delayed_job/browse_thread/thread/f7d0534bb6c7c83f/37b4e8ed7bfaba42 The problem is:… May 13, 2026 at 7:28 pm
  • Editorial Team
    Editorial Team added an answer There is a SDN article titled "Real Web Services with… May 13, 2026 at 7:28 pm

Related Questions

I want to clone multiple tables' rows that have a single primary key (PrimKey).
I want to write a non-CLR user-defined function in SQL Server 2005. This function
I am saving user-submitted HTML (in a database). I must prevent JavaScript injection attacks.
I'm attempting to deploy a WinForms app in a Citrix environment. It's been working
I've run into an issue that I need clearer heads to think through. Occasionally

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.