|
-
Oct 18th, 2011, 11:14 PM
#1
Thread Starter
Lively Member
ask - how to write to one field based info from another field
hi there,
I need help. I have 1 database, many tables.
here the situation:
I have 1 table which contain field_a,field_b,field_c,field_d --> table_1
I have 1 table which contain field_c,field_d, field_e --> table_2
in table_1, it is possible to have same record more than one in the field_c
in table_2, it is not allowed to have same record more than one in the field_c
what I need is:
I need to fill field_d in table_1 based on record in field_d on table_2, when field_c same each other (between table_1 and table_2).
I need to generate the code that can work like that.
I use MS SQL server to create database.
need help, please advice how to generate the code like that. thanks before
-
Oct 19th, 2011, 01:13 AM
#2
Re: ask - how to write to one field based info from another field
Code:
UPDATE table_1
SET table_1.field_d = table_2.field_d
FROM table_2
WHERE table_1.field_c = table_2.field_c
-
Oct 19th, 2011, 03:04 AM
#3
Thread Starter
Lively Member
Re: ask - how to write to one field based info from another field
 Originally Posted by jcis
Code:
UPDATE table_1
SET table_1.field_d = table_2.field_d
FROM table_2
WHERE table_1.field_c = table_2.field_c
hi there,
just as simple like that?anyway,I'll try. thanks before
-
Oct 19th, 2011, 04:19 AM
#4
Re: ask - how to write to one field based info from another field
Thread moved to the 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)
-
Oct 22nd, 2011, 04:22 AM
#5
Thread Starter
Lively Member
Re: ask - how to write to one field based info from another field
to jcis
thanks for your advice, it gave me idea to generate sql code.
now as my first purpose, I want to create one-click application for that.
can I do that in VB?thanks before
-
Oct 25th, 2011, 12:41 AM
#6
Re: ask - how to write to one field based info from another field
You mean if you can call SQL Updates like that one from VB? Yes, you can.
You just need to add a reference in your VB project to ADO library, then declare and instantiate a Conection object, set its ConnectionString property and open it. After that you can execute by doing like
Code:
CN.Execute "Update Table1..."
Don't forget to close your Connection when you don't need it anymore:
Code:
CN.Close
Set CN = Nothing
-
Oct 26th, 2011, 08:47 AM
#7
Thread Starter
Lively Member
Re: ask - how to write to one field based info from another field
yes correct.thanks very much.
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
|