0

Actually I’ve created a SQL Server table with a column name containing special characters like @#$$%Id%^$# and I have created an insert query to insert value such as:

Insert into MyTable ([@#$$%Id%^$#]) values (@@#$$%Id%^$#)  

After that passing parameter value as:

SqlCommand  cmd = new SqlCommand (“Insert into MyTable ([@#$$%Id%^$#]) values (@@#$$%Id%^$#) ”);
cmd.Parameters.Add(new SqlParameter (“(@@#$$%Id%^$#”, ParameterValue))

After executing this code I got

Must Declare Scalar Variable @

1
  • Don't edit in Word and paste here (smart quotes are not that smart). Commented Aug 24, 2012 at 15:37

1 Answer 1

4

This will never work:

Insert into MyTable ([@#$$%Id%^$#]) values (@@#$$%Id%^$#) 

Unless you have declared a variable this way:

DECLARE @@#$$%Id%^$# INT = 1;

However this is not valid syntax. So perhaps you meant to insert the entire value as a string:

Insert into MyTable ([@#$$%Id%^$#]) values ('@@#$$%Id%^$#')

Your use of a leading @ in the string is confusing - are you meaning that to be a parameter designation? This works fine for me:

CREATE TABLE dbo.MyTable([@#$$%Id%^$#] VARCHAR(255));

INSERT dbo.MyTable([@#$$%Id%^$#]) VALUES('@@#$$%Id%^$#');

DROP TABLE dbo.MyTable;
Sign up to request clarification or add additional context in comments.

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.