INSERT ... SELECT PROBLEM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • m3ckon

    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!
  • Hugo Kornelis

    #2
    Re: INSERT ... SELECT PROBLEM

    On 06 May 2004 15:26:50 GMT, m3ckon wrote:
    [color=blue]
    >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![/color]

    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)

    Comment

    • Serge Rielau

      #3
      Re: INSERT ... SELECT PROBLEM

      INSERT INTO T SELECT @orderid, S.* FROM S ?

      Cheers
      Serge
      --
      Serge Rielau
      DB2 SQL Compiler Development
      IBM Toronto Lab

      Comment

      • m3ckon

        #4
        Re: INSERT ... SELECT PROBLEM



        Thankyou ... that worked perfectly

        M3ckon

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

        Comment

        Working...