Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Combining 3 datatables to 1 new datatable.

Combining 3 datatables to 1 new datatable.

Scheduled Pinned Locked Moved Visual Basic
databasesales
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _teh_
    wrote on last edited by
    #1

    In my project I have 3 datatables with different data inside. I have datatables like:
    Customers:

    Customer number

    Name

    ID

    123450

    Customer A

    169

    987650

    Customer B

    753

    orders in last week:

    ID

    PCS

    169

    7

    753

    3

    and orders in sekond week in past:

    ID

    PCS

    169

    9

    753

    2

    Now I want to combine these tables data to table like next:

    Customer number

    Name

    ID

    1 week

    2 week

    123450

    Customer A

    169

    7

    9

    987650

    Customer B

    753

    3

    2

    I know this can be done with datarelation or with SQL inner join but idont have any

    M 1 Reply Last reply
    0
    • _ _teh_

      In my project I have 3 datatables with different data inside. I have datatables like:
      Customers:

      Customer number

      Name

      ID

      123450

      Customer A

      169

      987650

      Customer B

      753

      orders in last week:

      ID

      PCS

      169

      7

      753

      3

      and orders in sekond week in past:

      ID

      PCS

      169

      9

      753

      2

      Now I want to combine these tables data to table like next:

      Customer number

      Name

      ID

      1 week

      2 week

      123450

      Customer A

      169

      7

      9

      987650

      Customer B

      753

      3

      2

      I know this can be done with datarelation or with SQL inner join but idont have any

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      _teh_ wrote:

      I parse these datas from csv-file to in-memory datatables

      What makes you think you cannot create a datarelation for a dataset (a dataset is always an "in memory" construct). You will need to move the 3 tables to the 1 dataset and then create the realtions but this is easy using dataset.tables.add

      Never underestimate the power of human stupidity RAH

      _ 1 Reply Last reply
      0
      • M Mycroft Holmes

        _teh_ wrote:

        I parse these datas from csv-file to in-memory datatables

        What makes you think you cannot create a datarelation for a dataset (a dataset is always an "in memory" construct). You will need to move the 3 tables to the 1 dataset and then create the realtions but this is easy using dataset.tables.add

        Never underestimate the power of human stupidity RAH

        _ Offline
        _ Offline
        _teh_
        wrote on last edited by
        #3

        So this can be done with datarelations. I have not use datarelations before so could you please tell me how should I create the relation to get same result than with this SQL-code?

        SELECT a.customerID, a.Name, a.shop_id, ISNULL(sa.PCS1, 0) AS PCS1, ISNULL(sb.PCS2, 0) AS PCS2
        FROM customers AS a
        LEFT JOIN Shop1 AS sa ON (a.shop = sa.shop)
        LEFT JOIN Shop2 AS sb ON (a.shop = sb.shop)

        M 1 Reply Last reply
        0
        • _ _teh_

          So this can be done with datarelations. I have not use datarelations before so could you please tell me how should I create the relation to get same result than with this SQL-code?

          SELECT a.customerID, a.Name, a.shop_id, ISNULL(sa.PCS1, 0) AS PCS1, ISNULL(sb.PCS2, 0) AS PCS2
          FROM customers AS a
          LEFT JOIN Shop1 AS sa ON (a.shop = sa.shop)
          LEFT JOIN Shop2 AS sb ON (a.shop = sb.shop)

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Data relations are not the same as joins. Only the inner join is valid in a data relation. RTFM type in datarelation hit F1 for more details.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups