1

I can't for the life of me figure out why this query won't work no matter which one of my local databases I try (oracle, mysql, microsoft sql).

INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )

For example, with Microsoft SQL Server I get an Error near ','.

With MySQL I get

You have an error in your SQL syntax near '12345678, 123.04, 0, )' at line 2.

I've tried playing with it, I've looked at W3 school for the syntax of INSERT INTO. Everything looks good. What could it be?

Thank you!

EDIT:

As requested: here's the layout for mysql

+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| TestString | varchar(600) | NO   |     | NULL    |       |
| TestInt    | int(11)      | NO   |     | NULL    |       |
| TestDouble | double       | NO   |     | NULL    |       |
| Testbool   | tinyint(1)   | NO   |     | NULL    |       |
| TestDate   | date         | NO   |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+

Also, it should be noted I can run a parameterized query using these values and it will work just fine. It's only when I go to manually create the query that it's a problem.

Thenin
  • 127
  • 1
  • 1
  • 5

4 Answers4

2

There is nothing wrong with your schema or syntax, as you can see from this SQL Fiddle.

My guess is that you're running more than one statement at a time and not properly delimiting each one. For example:

INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )

INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )

Will cause an error. However:

INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' ); --End statement with ;

INSERT INTO testtable
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' );

...will run fine. It's also possible that you have a stray open-quote somewhere that isn't being closed, causing part of your statement to be the ending part of another string constant. Verify exactly what you're running, as the code you've posted will work fine as-is.

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
  • That would be what I think is happening. Something is getting caught between the end of the first string and the beginning of the second. However, I can't figure out how. Or why. – Thenin Sep 14 '12 at 05:18
1

format of the value depends on the dataType of your columns, but other hand always wrap you value with ' except int dataType

TRY

INSERT INTO testtable
VALUES ( 'testvalue' , '12345678', '123.04', '0', '1950-01-03' );
xkeshav
  • 53,360
  • 44
  • 177
  • 245
0
INSERT INTO testtable(column1,column2,column3,column4,column5) 
VALUES ( 'testvalue' , 12345678, 123.04, 0, '1950-01-03' )
Vikram Jain
  • 5,498
  • 1
  • 19
  • 31
0
INSERT INTO testtable (TestString,TestInt,TestDouble,Testbool,TestDate ) 
VALUES ( 'testvalue' , '12345678', '123.04', '0', '1950-01-03' )

Try This...