Results 1 to 7 of 7

Thread: ask - how to write to one field based info from another field

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    86

    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

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    86

    Re: ask - how to write to one field based info from another field

    Quote Originally Posted by jcis View Post
    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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    86

    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

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    86

    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
  •  



Click Here to Expand Forum to Full Width