|
-
Dec 11th, 2003, 12:09 PM
#1
Thread Starter
New Member
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
-
Dec 11th, 2003, 06:59 PM
#2
Member
Something like this or like that:
VB Code:
TBN$ = "CodeLinx": Set TB_Any = TB_CodeLinx
'create a temp field
1 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Creation d'un champs temporaire." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
SQL = "ALTER TABLE " & TBN$ & " ADD COLUMN ActeBackup TEXT(5)"
DB.Execute SQL
'take a copy of old data
2 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Copie de l'ancien data." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
SQL = "UPDATE " & TBN$ & " SET ActeBackup = Code"
DB.Execute SQL
' Remove Index
3 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration de l'index." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
SQL = "DROP INDEX code ON " & TBN$ ' DROP {TABLE table | INDEX index ON table}
DB.Execute SQL
'delete original field.
4 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration du champs original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
SQL = "ALTER TABLE " & TBN$ & " DROP COLUMN code"
DB.Execute SQL
'recreate original field.
5 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Création du champs original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
SQL = "ALTER TABLE " & TBN$ & " ADD COLUMN Code TEXT(5)"
DB.Execute SQL
'recreate original Indexes.
6 DB.Execute "CREATE UNIQUE INDEX Code ON " & TBN$ & " (Code)"
' Move back data in original field.
7 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Re-Création du data original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
Set TB_Any = DB.OpenRecordset(TBN$, dbOpenTable)
8 TB_Any.MoveFirst
While Not TB_Any.EOF
TB_Any.Edit
TB_Any("Code") = "0" & TB_Any("ActeBackup")
TB_Any.Update
TB_Any.MoveNext
Wend
TB_Any.Close
'now we got the data backin, delete the backup field
9 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration du champs temporaire." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..."
SQL = "ALTER TABLE " & TBN$ & " DROP COLUMN ActeBackup"
DB.Execute SQL
This is something I copied from somewhere and adjusted to my program. Big thank you for the original poster!
Bert
-
Dec 12th, 2003, 08:31 AM
#3
Fanatic Member
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. 
-
Dec 13th, 2003, 02:03 PM
#4
Hyperactive Member
insert into table t1 (select * from t2)
hopefully the structure of t1 and t2 are same
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|