By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,551 Members | 2,622 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,551 IT Pros & Developers. It's quick & easy.

INSERT ... SELECT PROBLEM

P: n/a
Hi there

I have a stored procedure which uses an INSERT ... SELECT statement to
transfer records from one table to another. However, I also need to
insert an extra field to the table which is from a parameter @orderid (
the field is called orderid)

Can someone tell me how this can be acheived??

At present I run the slect statment and then I add the parameter, by
doing an update query where the destination of field orderid is blank.
However I realise that this is not a particularly good or reliable way
of doing this.

I was wondering if anyone can help me at all ... please??

M3ckon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 06 May 2004 15:26:50 GMT, m3ckon wrote:
Hi there

I have a stored procedure which uses an INSERT ... SELECT statement to
transfer records from one table to another. However, I also need to
insert an extra field to the table which is from a parameter @orderid (
the field is called orderid)

Can someone tell me how this can be acheived??

At present I run the slect statment and then I add the parameter, by
doing an update query where the destination of field orderid is blank.
However I realise that this is not a particularly good or reliable way
of doing this.

I was wondering if anyone can help me at all ... please??

M3ckon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Hi M3ckon,

INSERT AnotherTable (Column1, Column2, ... ColumnN, OrderID)
SELECT Column1, Column2, ... ColumnN, @OrderID
FROM OneTable

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2

P: n/a
INSERT INTO T SELECT @orderid, S.* FROM S ?

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Jul 20 '05 #3

P: n/a


Thankyou ... that worked perfectly

M3ckon

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.