0

I made an insert statement that runs inside a asp.net page. It gave me an error, so I went to the sql server and ran the statement as it should be and used it to compare with what I wrote in the asp.net page. The thing is, it it writen properly but it doesn't work. It can't seem to detect the database or the tables at all and tells me the table doesn't exist and neither do the colums. The statement looks like this:

INSERT [Remisiones].[dbo].[Places] (Name, Type) VALUES ("Planta 1", "Planta")

I have also tried using [dbo].[Places] and simply Places but it gives me an error at the place of the table saying it is an Invalid object name. What is it doing?

2
  • PS assuming the table is where you say it is, the error is probably Invalid column name... Commented Jun 24, 2012 at 16:27
  • 1
    I think you should've taken a look on sql server tsql basics before. Commented Jun 24, 2012 at 17:01

1 Answer 1

7

Don't use double quotes for string delimiters; use single quotes.

INSERT [Remisiones].[dbo].[Places] (Name, Type) VALUES ('Planta 1', 'Planta');
Sign up to request clarification or add additional context in comments.

5 Comments

oh, ok. I was using mysql before and double quotes are accepted
To spare you unpleasant surprises should you ever use a standard compliant database: Quoting using square brackets is non-standard and only understood by SQL Server (and probably Sybase as it shared the same roots). The SQL standard uses double quotes to quote object names which works in SQL Server as well. You might get yourself used to writing "Remissiones" instead of [Remisiones] - or even better avoid object names that need quoting alltogether.
@a_horse_with_no_name to clarify you are talking about delimiting objects and entities, not strings. While I understand the argument for double quotes as opposed to square brackets in the case of objects or entities, in SQL Server I always prefer to avoid double quotes in both cases. As you can see double quotes are often mistaken for valid string delimiters, and seeing them anywhere might give the wrong perception. (And these days there isn't a whole lot of code being written that will port directly to another RDBMS.)
@AaronBertrand: absolutely. That's why I said "avoid object names that need quoting"
@a_horse_with_no_name I was merely clarifying because the question or answer wasn't talking about objects at all, just string literals. If someone just read the first two lines of your comment it might be confusing.

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.