Results 1 to 5 of 5

Thread: Merge Columns or Recordsets ?? [VB6]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question Merge Columns or Recordsets ?? [VB6]

    Given two SQL Tables [Client and Group], each table has 1 column (to simply things), a form [Frm], and a ComboBox [cb].

    For the SQL Tables:
    - Client has a column called CUSTOMER
    - Group has a column called GROUPNAME

    What I need is to display all values in column CUSTOMER (from Table Client) and GROUPNAME (from Table Group) in the Combobox as one column of choices.

    Currently I am easily able to do an SQL search on Client (get back a recordset) and use that as a datasource for my Combobox (works great) to display all Customers.

    So I need one of the following:
    - An SQL call that can take both tables and return a column with Customer and Groupname all in one
    - A way to merge two recordsets (I would do 2 SQL calls, one to generate the list of CUSTOMER and the other for GROUPNAMES then merge the recordset and display it)
    - Or a way to display 2 columns (either 2 columns in 1 recordset or 2 separate recordsets) as 1 in the Combobox.

    I hope that was a clear explanation.
    Any ideas would be appreciated.
    I might be going about this the wrong way.

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

    Select CUSTOMER From Client
    UNION
    Select GROUPNAME From Group


    nb: you will only get unique items, and it may be sorted alphabetically (depending on the database you use).

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    THANKS!

    And would that method be preferable to merging the recordsets after the SQL statement (individual SQL statements)?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    You cant really merge recordsets, the next best thing would be to add the items from one recordset to the combobox, then add the items from the other recordset (which would leave duplicates, unless you wrote code to stop that).

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308
    Thanks!
    Since I am using DataSources (and not adding the items) then using the given SQL Statement would probably be the best bet (if this actually puts them in the same Table/Column of the generated recordset).

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