1

I have this simple SQL query :

  UPDATE [mydb].[dbo].[EXPLANATIONS] 
  SET [EXPLANATION] = " This is the new explanation." 
  WHERE [RECORDNUMBER] = 123456 
    AND [EXPLANATIONNUMBER] = 7;

and I get this error :

Msg 207, Level 16, State 1, Line 1
Invalid column name ' This is the new explanation.' .

How can I get rid of this error and update the row correctly? Thanks.

1
  • 5
    Use the single quote. Instead of the " use ' So "This is the new explanation." this becomes 'This is the new explanation.' Commented Mar 13, 2015 at 7:37

3 Answers 3

5

Double quotes are usually used to object names (e.g. column name). That is part of SQL-92 standard.

In ANSI SQL, double quotes quote object names (e.g. tables) which allows them to contain characters not otherwise permitted, or be the same as reserved words (Avoid this, really).

single quotes to the string litral

  UPDATE [mydb].[dbo].[EXPLANATIONS] 
  SET [EXPLANATION] = 'This is the new explanation.'
  WHERE [RECORDNUMBER] = 123456 AND [EXPLANATIONNUMBER] = 7;
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of using double quotes, use single quotes like:

SET [EXPLANATION] = '<i>new explanation</i>'

Comments

1

We can update below table using double quotes as well, just add set statement above the query.

set QUOTED_IDENTIFIER  off

UPDATE [mydb].[dbo].[EXPLANATIONS] 
  SET [EXPLANATION] = "This is the new explanation."
  WHERE [RECORDNUMBER] = 123456 AND [EXPLANATIONNUMBER] = 7;


set QUOTED_IDENTIFIER  on

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.