#1
  1. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Posts
    790
    Rep Power
    30

    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
  3. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,594
    Rep Power
    278
    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 Give Rep button (bottom side on this reply ) and agree
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Posts
    790
    Rep Power
    30
    Thanks!

    That works good and a cleaner approach with coding it.

    I appreciate it.

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

IMN logo majestic logo threadwatch logo seochat tools logo