1

I'm having a problem with an insert query in SQL Server. The full text of the query is

insert into franchise (fran_id, name, address1, address2, city, state, zip, email, phone, text) 
values(0, "DevFranchise1", "101 Main St.", "-", "Brighton", "Mi", "48116", "[email protected]", 8105551234, "asdflkjsadf");

Now "state" and "text" both highligh blue. It gives me a list of errors like the following:

Msg 207, Level 16, State 1, Line 1
Invalid column name 'DevFranchise1'
Msg 207, Level 16, State 1, Line 2
Invalid column name '101 Main St.'

What does this mean / how can I fix it?

6 Answers 6

5

String literals should be in single quotes ('), not double quotes (").

Additionally, right angled brackets ([]) will allow you to use keywords (such as state and text) as column names. This is not always necessary, but provides a way out in ambiguous situations.

insert into franchise
    (fran_id, name, address1, address2, city, [state], zip, email, phone, [text])
values
    (0, 'DevFranchise1', '101 Main St.', '-', 'Brighton', 'Mi', '48116',
    '[email protected]', 8105551234, 'asdflkjsadf');
Sign up to request clarification or add additional context in comments.

2 Comments

and in the future I'd avoid using any keywords as a column name. If it turns blue like you describe, you know something is up...
Thanks for the help guys, my first time working on an IIS server.
5

Try to use single quotes (') instead of double (").

Otherwise, your values seem to be considered as column names.

Comments

2

use Single quotes and it will probably work.

Comments

1

You have to use single quotes in SQL.

Comments

1

Use the single quote character not the double quote character in SQL

Comments

1
set quoted_identifier off

before the insert.

But better is use single quotes.

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.