Results 1 to 8 of 8

Thread: SQL help INSERT and SELECT

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10
    How to combine both SELECt and INSERT statement together?
    I know the code below is wrong

    sql = "SELECT * FROM Orderitem WHERE InvoiceNumber = '" & invoiceid & "'" & " AND ItemNumber = " & itemid
    sql = sql & " AND INSERT INTO OrderItem(Quantity) VALUES(" & quantity & ")"

    Invoiceid is a string and the rest of the variables are long
    Ur help is deeply appreciated. Thanks


  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try:
    Code:
    INSERT INTO ...; SELECT ...
    Use a semicolon to separate the statements? It works on most DBs.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Then use the NextRecordset method of your recordset object to switch to the next recordset returned from that query

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10
    Originally posted by Clunietp
    Then use the NextRecordset method of your recordset object to switch to the next recordset returned from that query
    Sorry Clunietp, I dun get what u mean. Can u show me the code? Thanks

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What Tom means:
    Code:
    Dim rst as Recordset
    Set rst = db.OpenRecordset("INSERT ...; SELECT ...")
    ' It has executed both, and is holding results for
    ' the INSERT query. Time to move on to SELECT:
    rst.NextRecordset
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10
    Thanks for ur reply parksie. Sorry, I done my code this way
    If i put semicolon, an error msg will pop out and tell me there's an extra character, f i dun put, the error msg tells me there's a missing ;

    Dim de as demain 'demain is dataenvironment

    Set de = New demain

    sql = "INSERT INTO OrderItem(Quantity) VALUES(" & quantity & ");"
    sql = sql & " SELECT * FROM Orderitem WHERE InvoiceNumber = '" & invoiceid & "'" & " AND ItemNumber = " & itemid

    de.conordersys.Open
    de.conordersys.Execute sql
    de.conordersys.Close

    'conordersys is connection


    [Edited by opposite99 on 09-17-2000 at 01:16 PM]

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It complains because .Execute queries cannot return a recordset. For that, you'd have to use the Recordset object. What DB interface are you using? (DAO/ADO/RDO/other)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10
    Originally posted by parksie
    It complains because .Execute queries cannot return a recordset. For that, you'd have to use the Recordset object. What DB interface are you using? (DAO/ADO/RDO/other)
    I'm using Dataenvironment only

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width