Thread: Select field in table - insert into another table

Results 1 to 3 of 3
Share This Thread →
  1. #1
    phoenixaz is offline Contributing User ASP Free Novice (500 - 999 posts)
    Join Date
    Feb 2008
    Posts
    780
    Rep Power
    29

    Select field in table - insert into another table

    I want to insert into a newly created TABLE2, the email field in TABLE1.

    This is a sql database.

    Doesn't seem to work. Am I making this more complex then necessary?

    I appreciate your help.


    Code:
    set conndatabase = server.CreateObject("adodb.connection") 
    conndatabase.open application("connectionstring")
    
     
    sql = "select email from TABLE1
    
    set rs = server.createobject("adodb.recordset")
    set rs = conndatabase.execute(sql) 'get file data as recordset
    
    do until rs.eof
       
    If rs("email") <> "" Then
         email = replace(rs("email"),"'","`")
    End if
    
    
    sql = "insert into TABLE2(email)values (" &_
    		
    			"'" & email & "')"																
    			
    conndatabase.execute(sql)
       
    
    rs.movenext
    loop
    
    Response.Write "done"

  2. #2
    gk53's Avatar
    gk53 is offline Contributing User ASP Free Beginner (1000 - 1499 posts)
    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,223
    Rep Power
    263
    you can do something like that
    Code:
    <%
    set conndatabase = server.CreateObject("adodb.connection") 
    conndatabase.open application("connectionstring")
    
     
    sql = "select email from TABLE1"
    
    set rs = server.createobject("adodb.recordset")
    rs.open sql, conndatabase
    
    do until rs.eof
       
    If rs("email") <> "" Then
        email = replace(rs("email"),"'","`")
        sql = "insert into TABLE2(email)values (" & "'" & email & "')"																
        conndatabase.execute(sql)
    End if
    rs.movenext
    loop
    
    Response.Write "done"
    Comments on this post
    • phoenixaz → agrees: Works well - thanks
    GK
    __________________________________________________ _____
    if you found this post is useful click scale (right side on this reply ) and agree

  3. #3
    phoenixaz is offline Contributing User ASP Free Novice (500 - 999 posts)
    Join Date
    Feb 2008
    Posts
    780
    Rep Power
    29
    Thanks!

    That works good and a cleaner approach with coding it.

    I appreciate it.

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Table in select field
    By terroraapje in forum HTML, JavaScript And CSS Help
    Replies: 0
    Last Post: November 10th, 2010, 03:32 AM
  2. Replies: 1
    Last Post: August 25th, 2006, 09:29 PM
  3. Insert Records from select query into table
    By ShannyFE in forum Microsoft SQL Server
    Replies: 2
    Last Post: June 24th, 2006, 05:23 AM
  4. INSERT \ into mySQL table field
    By markoc in forum ASP Development
    Replies: 2
    Last Post: November 4th, 2005, 07:44 AM
  5. Can you INSERT INTO table with SELECT.. UNION queries
    By birdfeeder in forum Microsoft Access Help
    Replies: 3
    Last Post: March 30th, 2005, 05:28 AM

ASP Free Advertisers and Affiliates