none
sql query help RRS feed

  • Question

  •  

    I am writing a dynamic query

    insert into Tablename select '1111',

    name,address,phone,'1111', exec usp_storedProcedureName '1111', '1111', 'KA','EA'

    from edi856Item

    where autoid = '1111'

     

     

    I dont know why I am getting this error i think there is some syntax error:

    Msg 156, Level 15, State 1, Line 3

    Incorrect syntax near the keyword 'exec'.

    Msg 156, Level 15, State 1, Line 5

    Incorrect syntax near the keyword 'from'.

     

     

    Can anyone help please

     

    Tuesday, April 8, 2008 4:35 PM

Answers

  • You can't use the EXEC statement as part of the projection of a query.  You are probably confusing "INSERT INTO table_name EXEC procedure_name" and "INSERT INTO table_name SELECT ...".
    Those are two distinct versions of the INSERT statement that cannot be mixed.  You could use "SELECT function_name() ..." depending on what you are trying to project.
    Tuesday, April 8, 2008 8:16 PM