hat is wrong with this insert statement?

  • There is a syntax problem with the third column b.id and the last ')'.

    But I cant figure out why.

    Can someone help me? I need to get this done tonight:(

    [Code="sql"]

    INSERT into user_def_fields

    ('VMPRTMNT','UDF-0000022',b.ID,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,b.[Create date])

    SELECT

    b.ID,

    b.[Create date]

    FROM wmvw_PartCreateDate as b

    [/code]

  • What goes inside the brackets in your INSERT () are the column names in the table you're inserting into. You have a bad mix of the INSERT ... VALUES form and the INSERT ... SELECT form of insert. I suggest you open up Books Online and have a look at the two forms.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Gail,

    Thank you.

    Still downloading BOL to my new laptop. Another 6 minutes to go.

    But your comments really helped I think.

    Would this work?

    INSERT into user_def_fields

    (

    program_id,

    id,

    Document_id,

    Line_no,

    Del_Line_no,

    Label,

    Data_Type,

    Display_Format,

    Tab_or_Table,

    Tab_ID,

    Table_ID,

    Sequence_No,

    UDF_Required,

    String_Val,

    Number_Val,

    Bool_Val,

    date_val

    )

    SELECT

    'VMPRTMNT',

    'UDF-0000022',

    b.ID,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    NULL,

    b.[Create date]

    FROM wmvw_PartCreateDate as b

  • Yes, It will work

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • TC-416047 (12/1/2013)


    Would this work?

    Wouldn't it be faster to run it and see if it works?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • yes...

    I did...

    It worked...

    Thank you for helping.

    -Todd

Viewing 6 posts - 1 through 5 (of 5 total)

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