Fill the column data with specific row value

  • I have 2 tables: A and B

    This is the result obtained:

    PKCostCenterAmountAssignment Xfd1

    501002101250.00T0250076 100210

    501002101250.00T0250076 100210

    401002501250.00T0250076100250

    401003701250.00T0250076100370

    Now here is my question:

    In the Xfd1 column first 2 values are "100210" but there I want "100250 and 100370" respectively. This result is obtained by doing union all operation on tables. From 1st table I got 1st 2 records and then from 2nd table I got remaining rows. And then I did union all.

  • please send DDL and elaborate your question.

  • Sorry, my mistake, A and B are not the tables, just ignore that sentence.

    There are many tables which are joined to build the 2 result set and then these 2 result set are combined using union all to get the above result.

    There is no ddl stmt here. Tables are already created.

  • Hi UNION ALL does not give in build ordering functionality .

    so use in line view (Sub query) Like

  • SELECT PKCostCenterAmountAssignment Xfd1 FROM

    (

    SELECT PKCostCenterAmountAssignment Xfd1 FROM a

    UNION ALL

    SELECT PKCostCenterAmountAssignment Xfd1 FROM a

    )temp ORDER BY CostCenter DES

  • Or use CTE ..

    ,WITH TEMP AS (

    SELECT PKCostCenterAmountAssignment Xfd1 FROM a

    UNION ALL

    SELECT PKCostCenterAmountAssignment Xfd1 FROM a

    )

    SELECT PKCostCenterAmountAssignment Xfd1 FROM TEMP

    ORDER BY CostCenter DES

  • Let me clarify my question.

    PKCostCenterAmountAssignment Xfd1

    501002101250.00T0250076 100210

    501002101250.00T0250076 100210

    401002501250.00T0250076 100250

    401003701250.00T0250076 100370

    I want "100250" and "100370" (which is in CostCenter column in 3rd and 4th row) to be filled in place of 100210( which is in Xfd1 column in 1st and 2nd row)

  • Sorry, but my crystal ball is in the shop still. You haven't provided nearly enough information to really help you as we can't see from here what you see there. You have access to your tables, data, and understand what you are trying to accomplish even though you can't figure out how to get from A to B.

    You need to provide us with the information we need to help you. Start by reading the first article I reference below in my signature block. It will walk you through the steps to post the necessary information for us to help you.

    Please understand, that when we ask for sample data, we really don't want sensitive company data, just something you make up that is representatitve of the problem domain and that you can map back to your actual data.

  • question is still not clear

  • sandeep rawat (8/28/2012)


    question is still not clear

    +1 - no idea what's going on here!

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (8/28/2012)


    sandeep rawat (8/28/2012)


    question is still not clear

    +1 - no idea what's going on here!

    I think the Hudson is clearer than this question.

  • Viewing 9 posts - 1 through 8 (of 8 total)

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