Results 1 to 4 of 4

Thread: How do you insert all the information from one table to another table using sql comma

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    1

    How do you insert all the information from one table to another table using sql comma

    How do you insert all the information from one table to another table using sql command n vb? thanks in advance

  2. #2
    Member Birth's Avatar
    Join Date
    Jan 2003
    Location
    Montreal
    Posts
    57
    Something like this or like that:
    VB Code:
    1. TBN$ = "CodeLinx": Set TB_Any = TB_CodeLinx
    2.  
    3.    'create a temp field
    4. 1  Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Creation d'un champs temporaire." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
    5.    SQL = "ALTER TABLE " & TBN$ & " ADD COLUMN ActeBackup TEXT(5)"
    6.    DB.Execute SQL
    7.    
    8.    'take a copy of old data
    9. 2  Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Copie de  l'ancien data." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
    10.    SQL = "UPDATE " & TBN$ & " SET ActeBackup = Code"
    11.    DB.Execute SQL
    12.    
    13.    ' Remove Index
    14. 3  Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration de l'index." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
    15.    SQL = "DROP INDEX code ON " & TBN$   ' DROP {TABLE table | INDEX index ON table}
    16.    DB.Execute SQL
    17.    
    18.    'delete original field.
    19. 4  Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration du champs original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
    20.    SQL = "ALTER TABLE " & TBN$ & " DROP COLUMN code"
    21.    DB.Execute SQL
    22.    
    23.    'recreate original field.
    24. 5  Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Création du champs original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
    25.    SQL = "ALTER TABLE " & TBN$ & " ADD COLUMN Code TEXT(5)"
    26.    DB.Execute SQL
    27.    
    28.    'recreate original Indexes.
    29. 6  DB.Execute "CREATE UNIQUE INDEX Code ON " & TBN$ & " (Code)"
    30.    
    31.    ' Move back data in original field.
    32. 7  Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Re-Création du data original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
    33.    Set TB_Any = DB.OpenRecordset(TBN$, dbOpenTable)
    34.    
    35. 8  TB_Any.MoveFirst
    36.    
    37.    While Not TB_Any.EOF
    38.       TB_Any.Edit
    39.       TB_Any("Code") = "0" & TB_Any("ActeBackup")
    40.       TB_Any.Update
    41.       TB_Any.MoveNext
    42.    Wend
    43.    
    44.    TB_Any.Close
    45.    
    46.    'now we got the data backin, delete the backup field
    47. 9  Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration du champs temporaire." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
    48.    SQL = "ALTER TABLE " & TBN$ & " DROP COLUMN ActeBackup"
    49.    DB.Execute SQL
    This is something I copied from somewhere and adjusted to my program. Big thank you for the original poster!

    Bert

  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    This will create table 2 and copy all the data from table 1 into it.

    SELECT *
    INTO TABLE_2
    FROM TABLE_1

    This will just copy all the data from table 1 into table 2

    INSERT INTO TABLE_2 (Field_1, Field_2)
    SELECT Field_1, Field_2
    FROM TABLE_1
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  4. #4
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    insert into table t1 (select * from t2)

    hopefully the structure of t1 and t2 are same
    Regards

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