SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: syntax question

  1. #1
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question syntax question

    hi there i have a table which i want to copy all the records from one table to another, (many different serialno. with the same product name) and at the same time delete those existing records in the table i did the following:
    Code:
    sql3 = "SELECT * FROM Serial WHERE PurchaseInvNo = '"&RS("PurchaseInvNo")&"'"
    Set RS4 = objConn.Execute(sql3) 
     
    While NOT RS4.EOF 
    Dim insertQuery
    insertQuery = "INSERT INTO PurgedSerial VALUES "&_
    "('"&RS4("SerialNo")&"', '"&RS4("PartNo")&"', '"&RS4("SalesInvNo")&"', '"&RS4("PurchaseInvNo")&"');"
     
    objConn.Execute(insertQuery) 	
     
    Dim deleteSQL3
    deleteSQL3 = "Delete From Serial Where PurchaseInvNo='"&RS4("PurchaseInvNo")&"'"
    	 'Response.Write(deleteSQL)
    	 objConn.Execute(deleteSQL3) 	 
     
    RS4.MoveNext
    Wend
    but it seems that the insert query only inserts one record (it doesnt seem to move next)while all deleted query deletes all the records that are stated

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your insert query isn't specifying the field names.

  3. #3
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope that isnt the reason.. its got something to do with my looping haha i think

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you think it has somethin to do with your looping why don't you try something like...
    although, you should definitely fix your insert statement.

    Code:
    sql3 = "SELECT * FROM Serial WHERE PurchaseInvNo = '"&RS("PurchaseInvNo")&"'"
    Set RS4 = objConn.Execute(sql3) 
     
    While NOT RS4.EOF 
    Dim insertQuery
    insertQuery = "INSERT INTO PurgedSerial VALUES "&_
    "('"&RS4("SerialNo")&"', '"&RS4("PartNo")&"', '"&RS4("SalesInvNo")&"', '"&RS4("PurchaseInvNo")&"');"
     
    'objConn.Execute(insertQuery) 	
    Response.write InsertQuery  & "<BR><BR>"
     
    Dim deleteSQL3
    deleteSQL3 = "Delete From Serial Where PurchaseInvNo='"&RS4("PurchaseInvNo")&"'"
    	 'Response.Write(deleteSQL)
    	 objConn.Execute(deleteSQL3) 	 
     
    RS4.MoveNext
    Wend

  5. #5
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried that but it doesnt work properly haha

    only one record gets inserted and all the records in the other table get deleted. Its supposed to insert all the records and delete as well

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My code above isn't support to insert anything, it's supposed to print your Insert statement to the screen...ie, if you only see one insert statement, there is NO WAY anything more than one row is gettin inserted.

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh - it's pretty obvious.

    If your SELECT query is returning multiple records, then the first time that you run your DELETE query, they are all being deleted (look at the queries the WHERE conditions are the same).

    Change your delete query to:
    Code:
    deleteSQL3 = "DELETE FROM Serial WHERE SerialNo='" & RS4("SerialNo") & "' AND PartNo='" & RS4("PartNo") & "' AND SalesInvNo='" & RS4("SalesInvNo") & "' AND PurchaseInvNo='" & RS4("PurchaseInvNo") & "'"

  8. #8
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    o ok thanks ! its working fine now

Bookmarks

Posting Permissions

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