"Insert" Problems

  • Hi,

    I am writing a stored procedure that will import records in one table from many different tables and stored procedures.  My problem is that the stored procedures are returning records with only two columns, while my table has 4.  I would like to insert some constant values for the missing columns and I don't know how to implement this in the insert statement.  It gives me an error message saying that column names are not permitted.  Also, the order of the returned columns is not the same as the order in receiving table.

    Any help will be greatly appreciated.

  • I think the simplest way would be to create a temp table and keeping on adding records as and when you reterive it. And then in the end you can just import records into the main table.

     

    HTH

  • write down the Columns names in insert into.

    you should do something like this (for example take from Order and put into Invoice table) :

    INSERT INTO Invoice ( Order_no, Inv_NO, DEPT, CUST_ID)

    SELECT  OrderID, 100, 1, CustomerID,

    FROM Orders with (nolock)

    WHERE Orders.OrderID>10

    I hope this help u


    Alamir Mohamed
    Alamir_mohamed@yahoo.com

  • There can be two solutions for this problem:

    1) Specify the default values for the columns in the table structure itself and specify the column list in insert statement.

    2) Add the values for the columns for which you want to pass constant values at the same place where you are providing the other values.


    Best Regards,

    Indu Jakhar

  • Thank you very much for your help.

    I specified column names in my insert statement and implemented the missing values in the Select statement, so that my Select statement is retrieving 4 columns even though the source table has only two.  The other two are constant values.

    Again, Thank you.

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

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