1

Below code saying error

incorreect syntax near "Main"

  INSERT INTO tbl  (
    'Week', 
    Main, 
    a, 
    b, 
    c, 
    d, 
    e                     
    )
    Select  'Week', 
    Main, 
    a, 
    b, 
    c, 
    d,
    e   
    FROM    tbl_link
2
  • Could you please post the definition for tbl? Commented Sep 14, 2009 at 12:24
  • did you really select an answer that didn't work? Commented Sep 14, 2009 at 13:03

4 Answers 4

2
INSERT INTO tbl  (
    'Week', 

You should insert actual field name here.

If you field is called Week, just get rid of the quotes:

  INSERT INTO tbl  (
        Week, 
        Main, 
        a, 
        b, 
        c, 
        d, 
        e                     
        )
        Select  'Week', 
        Main, 
        a, 
        b, 
        c, 
        d,
        e   
        FROM    tbl_link

, otherwise substitute the field name.

Sign up to request clarification or add additional context in comments.

Comments

2

To clarify the other answers:

SQL INSERT syntax with SELECT statements is as followings:

INSERT INTO Table(Column1Name, Column2Name, ...)
SELECT
Column1Data, Column2Data, ...
FROM Table

The parenthesized list after the table name you intend to update is the ordered list of columns on that table that you intend to populate. It does not represent data that will make its way to the table.

Comments

0
  INSERT INTO tbl  (
        [Week], 
        Main, 
        a, 
        b, 
        c, 
        d, 
        e                     
        )
        Select  [Week], 
        Main, 
        a, 
        b, 
        c, 
        d,
        e   
        FROM    tbl_link

Comments

0

there are two possible issues here:

  • Your column "week" is a reserved word, so use square braces: [week] when you refer to it in any query.
  • Based on your INSERT attempt, your tables tbl and tbl_link must should both have columns named: [week],Main,a,b,c,d, and e. If not you must rethink what you are trying to do. The first list of columns have to all exist within table tbl, and the second list of columns must all be within table tbl_link. If there are column in tbl that are not in tbl_link, you can just eliminate them from the INSERT:

    INSERT INTO tbl ( [Week], a, b, c ) Select [Week], a, b, c FROM tbl_link

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.