chobo
chobo

Reputation: 32301

What is wrong with this insert query?

I am trying to run the following query in ms sql manager, but I keep getting syntax errors.

Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ' '.

INSERT INTO dbo.Survey 
(
    Title, 
    Active, 
    StartDate, 
    EndDate
)
VALUES  
(
    'Title test', 
    '1', 
    null, 
    null
);



// Table
SurveyId (primaryId)
Title  (varchar)
Active (bit)
StartDate (datetime)(nullable)
EndDate (datetime)(nullable)

Upvotes: 2

Views: 297

Answers (4)

HLGEM
HLGEM

Reputation: 96640

Also, your table structure doesn't indicate if it is an indentity key. If it is not, the PK is required and thus must have a value to be inserted.

Second possiblity, the error is on a trigger on the table.

Upvotes: 1

Jeff
Jeff

Reputation: 388

I've seen problems where a cut & paste between a unicode and non-unicode document looks fine, but acts strangely with different versions of SQL Server.

One thing I've done to fix this in the past is to do a Save As "with encoding" in Management Studio then select something like "Western European (Windows) - Codepage 1252.

To get the advanced save options, do a File, Save as, then click the arrow on the far right side of the save button and change to "Save with encoding".

Another solution would be to use something like PureText (free s/w) to cut & paste your code without having to go into Notepad as a middle step.

http://www.stevemiller.net/puretext/

Hope this helps!

Upvotes: 0

fdaines
fdaines

Reputation: 1246

try inserting 1 or b'1' value to Active column

Upvotes: 0

SQLMenace
SQLMenace

Reputation: 135171

Incorrect syntax near ' '

Double click on the error, it will bring you to the line in question

It looks like you have a blank character of some sort on line 8 (after Values)..paste it into something like NotePad++ and look for hidden characters

or change

VALUES  
(

to

VALUES(

Upvotes: 7

Related Questions