How to Get data from Table2 instead of Table 1?

  • Kindly help me my requirement?

    I have two tables and similar column like (year, week, day, and shifts, Totalvalue)

    Table 1 having full data of 2013 but Table2 few weeks of a month.

    Also

    Some Total value has changed in Table2 for a particular week so here we consider Table2.

    Some records having similarly in both table.

    Few days missing a week in Table2

    Few days missing a week in Table1.

    My requirement

    Whenever full the records from Table 1 and Table 2 but if data exist in table 2, Get data from table 2 if does not exist get data from Table 1 for passing parameter to particular month.

    How to get it..

    please give Query for the same. Thanks.

  • Based on what you have posted, really can't provide much help.

    Please read the first article I reference in my signature block below. Following the instructions in it regarding the information you need to post and how to do it to get the best possible answers to your questions.

  • Impossible to "give a query" as Lynn states. You will need to post table definitions with sample data scripts to get a query.

    Try full outer joining the two tables on whatever constitutes the primary key.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • manavairajan (3/1/2014)


    Kindly help me my requirement?

    I have two tables and similar column like (year, week, day, and shifts, Totalvalue)

    Table 1 having full data of 2013 but Table2 few weeks of a month.

    Also

    Some Total value has changed in Table2 for a particular week so here we consider Table2.

    Some records having similarly in both table.

    Few days missing a week in Table2

    Few days missing a week in Table1.

    My requirement

    Whenever full the records from Table 1 and Table 2 but if data exist in table 2, Get data from table 2 if does not exist get data from Table 1 for passing parameter to particular month.

    How to get it..

    please give Query for the same. Thanks.

    Gosh. Isn't this just a simple MERGE or "Upsert" to Table1 from Table2?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply