467,915 Members | 1,150 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

INSERT ... SELECT PROBLEM

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
  • viewed: 1940
Share:
3 Replies
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
INSERT INTO T SELECT @orderid, S.* FROM S ?

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


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.

Similar topics

16 posts views Thread by Philip Boonzaaier | last post: by
7 posts views Thread by anu b | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.