Insert Into Statement

  • Hi,

    I am getting "incorrect syntax near ','" error while inserting data into database. The reason, I am having this error is that I have Insert into statement as

    INSERT INTO TableName VALUES ('column1', 'column 2', 'column 3', , 'Column 5', 'Column 6')

    Now you see the comma after column 3 is giving an error. So, at Column 4 I am trying to insert null value for Integer data type.

    So, definitely, I am doing something wrong here. My question is then, how to insert a null value in column with datatype integer.

    Thanks,

  • there are two ways;

    you can not refer to the column at all, or you need to use the NULL keyword explicitly:

    --define the columns being inserted, skip #4

    INSERT INTO TableName (col1, col2, col3 , col5, col6)

    VALUES ('column1', 'column 2', 'column 3', 'Column 5', 'Column 6')

    --or

    INSERT INTO TableName VALUES ('column1', 'column 2', 'column 3',NULL , 'Column 5', 'Column 6')

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you

    This answer my question.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply