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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:38:17+00:00 2026-05-15T04:38:17+00:00

how to pass column name with parameter in insert sql statment e.g. @name=’name’ insert

  • 0

how to pass column name with parameter in insert sql statment
e.g.

@name='name'
insert into employees (id,@name) values(1,'a')

is this possible?

  • 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-15T04:38:17+00:00Added an answer on May 15, 2026 at 4:38 am

    No it isn’t possible you would need to build the SQL Statement including the column either in your application or by using dynamic SQL in SQL Server itself.

    Edit: RE: “what’s dynamic sql”. The approach is as follows.

    DECLARE @Value nvarchar(100)
    DECLARE @InsertString nvarchar(1000)
    DECLARE @name sysname
    
    SET @name ='name'
    SET @Value = 'a'
    
    SET @InsertString= 'INSERT INTO EMPLOYEES (id,' + @name + ') values(1, @Value)'
    
    
    EXEC sp_executesql @InsertString, N'@Value nvarchar(100)', @Value 
    

    However there are 2 issues with it. First @name must be SQL Injection proof. For the same reason you would also want to use a parameter for @Value. However the data type for that must be specified in advance meaning that it won’t be suitable for all columns. So on reflection you would be better off doing this in your application layer. (NB: The same considerations about SQL injection still apply and your application code will need to add the parameter of the correct type for the column)

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

Sidebar

Related Questions

Is it possible to pass the coloumn name also like a variable.Please edit this
Possible Duplicate: Pass a data.frame column name to a function I am trying to
Is it possible to alias a column name and then use that in a
I want to pass a table name as a parameter in a Postgres function.
I'd like to pass a table as a parameter into a scaler UDF. I'd
I have a column 'name' in Database which has values as 'john,smith'. I'm passing
In my stored procedure I have to pass a table and column name which
I would like to pass data from a database column to another page via
Pass a []byte into a template as the body of a message post on
Possible Duplicate: Change Notification with Sql Server 2008 Am just wondering is there's anyway

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.