views:

79

answers:

6

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?

A: 

You have to use single quotes in SQL.

cdonner
+4  A: 

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

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

Peter Lang
A: 

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

Hogan
+1  A: 

use Single quotes and it will probably work.

Younes
+4  A: 

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');
Thorarin
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...
Bob Pusateri
Thanks for the help guys, my first time working on an IIS server.
Josh K
A: 
set quoted_identifier off

before the insert.

But better is use single quotes.

guille