Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005
    Location
    Brooklyn, ny
    Posts
    69

    Unanswered: merge two tables

    Hello, I need your expert help:

    I have two tables (ship2005 and ship2006) all with same structure
    Sold_to
    Week
    Year
    Units
    Dollars
    Style

    I have to merge them together, and add some other columns from other tables
    Custmstr (director) and stylemstr (style) based on Sold_to

    In the format so I’m able to see 2005 week, 2006 week, 2005 unit, 2006 unit, 2005 dollars, 2006 dollars and so on.

    This one is working, but forever…

    where Custmstr.Sold_to *= ship2005.Sold_to
    and Custmstr.Sold_to *= ship2006.Sold_To
    and stylmstr.style_num *= ship2005.style_number
    and stylmstr.style_num *= ship2006.style_number

    And another thing: how can I populate the Year column for both?

    Thank you very much

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Please provide some sample output so we can see where you want to go with this.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Sep 2005
    Location
    Brooklyn, ny
    Posts
    69
    Sold_to Director Style Year Week Units05 Units06 Dollars05 Dollars06
    18 6 8433 2006 1 6 67
    24 6 2599 2006 1 2 30
    24 6 2604 2006 1 1 17
    24 6 2604 2005 1 1 13
    24 6 2788 2006 1 1 15

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Use a UNION query to combine the two datasets.

    Use a CROSSTAB query to generate the layout you want, with separate headers for each year. Books Online has an excellent explanation of how to create a CROSSTAB query using TSQL CASE statements.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Sep 2005
    Location
    Brooklyn, ny
    Posts
    69
    Thank you, done reading CROSSTAB ...all works fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •