1

I have come across a situation where a column name in the SQL database is [column name] and I am trying to update it by that column.

Selecting is easy: Select [column name] from MyDatabase.

I am trying to do this (parameterized): UPDATE MyDatabase WHERE [column name] = @[column name]

the errors say: column name does not exist: @column

I cant just change the name in the database because it has been around for a while and it will most likely break a bunch of stuff.

Thank you all for your help!

Dave

3
  • UPDATE MyTable,not mYDb Commented Aug 29, 2013 at 15:15
  • in sqlserver I think is @variables,parameters cannot have spaces Commented Aug 29, 2013 at 15:15
  • If this is SQL-Server specific, please remove the MySQL tag. Commented Aug 29, 2013 at 15:23

4 Answers 4

4

The parametername does not have to match the column name. (In fact, it cannot have spaces) Just change your parameter name to not include a space.

 UPDATE MyDatabase WHERE [column name] = @columnname 
Sign up to request clarification or add additional context in comments.

Comments

0

Parameter/variables cannot have spaces in them. But then again they do not have to match column names.

You can have something like

UPDATE MyDatabase WHERE [column name] = @column_name 

Comments

0

According to http://technet.microsoft.com/en-us/library/ms176027(v=sql.105).aspx :

Microsoft SQL Server does not recognize variable names and stored procedure parameters that are delimited. These types of identifiers must comply with the rules for regular identifiers.

This means you can't use @[variable name] in your code. You have to make do with @variable_name or similar.

Comments

0
UPDATE MyTable WHERE [column name] = @this_is_parameter_name 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.