June 1, 2004 at 11:42 am
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.
June 2, 2004 at 4:19 am
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
June 2, 2004 at 4:21 am
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
June 2, 2004 at 6:00 am
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.
Indu Jakhar
June 2, 2004 at 6:13 am
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