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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:30:32+00:00 2026-05-24T11:30:32+00:00

Using MS SQL Server but porting on MySQL so I need a solution for

  • 0

Using MS SQL Server but porting on MySQL so I need a solution for both ideally (but MySQL preferably)

I am trying to concatenate two field in order to specify the field name for the select statement.

Example table:

id     | name
1      | John
2      | Bob


SELECT id, 'na'+'me' as value FROM table WHERE 1=1

actual return (of course)

id     | value
1      | name
2      | name

expected return:

id     | value
1      | John
2      | Bob

I have no clue as to how to specify that the concatenate result is to be used as field name, and not as result.

  • 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-24T11:30:32+00:00Added an answer on May 24, 2026 at 11:30 am

    I’m confused by your question but the query you need to get the expected return is simply:

    SELECT id, name as value FROM Table
    

    This will work in both mySQL and SQL Server

    UPDATE:

    It just occured to me that you might be talking about specifying which column to select using concatenated values. To do this in SQL Server use dynamic SQL. Example:

    EXEC('SELECT id, ' + 'na' + 'me' + ' as value FROM table WHERE 1=1')
    

    The above would be pointless if that’s how you actually plan on using it. If na and me are parameters or something this would make sense. Be sure to read this article before using Dynamic SQL in SQL Server.

    MySQL Version:

    mysql> set @sql_text := 'SELECT id, ' + 'na' + 'me' + ' as value FROM table WHERE 1=1';
    
    mysql> prepare stmt from 
        -> @sql_text
    
    mysql> EXECUTE stmt
    

    Lifted from here.

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

Sidebar

Related Questions

My problem relates to trying to include an SSRS (SQL Server) Report inside my
I am trying to create an SQL Server Compact edition in SQL Server Management
I've been writing asp.net apps with SQL Server back ends for the past 10
I'm porting a process which creates a MASSIVE CROSS JOIN of two tables. The
I have a SQL Server DB with the following tables and relationships: Jobs which
i am preparing myself for importing data from excel sheet to sql server 2005.I
How to get the sheet names in an Excel file using SQL Sever 2005?
Making my first steps with NHibernate, I'm trying to have it creating my Tables
I want to copy all my database to remote database server. I have access
I've read every response I could fine on SO before posting this question. Although

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.