Converting columns in to rows

Hi All,
Can any one plzz help me out how to convert columns in to rows.
I am having data as follows:
Date1 Date2 Date3 Date4 Date5 Date6
I need the Out put as Below
Date
Date1
Date2
Date3
Date4
Date5
Date6
Thanks in Advance
Regards
Praveen

you can do this by using OTN's search engine:
http://forums.oracle.com/forums/search.jspa?objID=f75&q=converting+columns+into+raws

Similar Messages

  • Converting column store to row store

    Hello Everyone,
    I have a question related to the Column store to Row Store conversion:
    Is it always necessary to perform the conversion when all connections to the system have been stopped from the application level?
    what would be the loss if the conversion is performed with the applications or connections to the system still open?
    Regards,
    Vinay

    Hi Vinay,
    Can you explain your questions more clearly? Do you mean convert a column table to a row table?
    Best regards,
    Wenjun

  • Converting columns to single row

    Hi,
    I have scenario like this
    bw_we     account        user_defined1      user_defined2         user_defined3
    'abc'           1234           5678                    6789                         0987
    abc             2424           64635                  8977                         789534
    def             44382         4924929                 9449                       242424
    def            42488           88488                  888324                     8888i need to get result set as
    gl_account
    1234
    5678
    6789
    0987
    2424
    64635     
    8977     
    789534
    .all the values in each row should be converted into one column..is there any oracle function do this?

    In 10g you'll have to do something like the following to UNPIVOT the results:
    SQL> WITH test_data AS
      2  (
      3          SELECT 'abc' AS BW_WE,   1234 AS ACCOUNT,       5678 AS USER_DEFINED1,   6789 AS USER_DEFINED2,    0987 AS USER_DEFINED3 FROM DUAL UNION ALL
      4          SELECT 'abc' AS BW_WE,   2424 AS ACCOUNT,       64635 AS USER_DEFINED1,   8977 AS USER_DEFINED2,   789534 AS USER_DEFINED3 FROM DUAL UNION ALL
      5          SELECT 'def' AS BW_WE,  44382 AS ACCOUNT,       4924929 AS USER_DEFINED1, 9449 AS USER_DEFINED2,   242424 AS USER_DEFINED3 FROM DUAL UNION ALL
      6          SELECT 'def' AS BW_WE,  42488 AS ACCOUNT,       88488 AS USER_DEFINED1,   888324 AS USER_DEFINED2, 888 AS USER_DEFINED3 FROM DUAL
      7  )
      8  -- END SAMPLE DATA
      9  SELECT  DECODE
    10          (
    11                  RN
    12          ,       1,      ACCOUNT
    13          ,       2,      USER_DEFINED1
    14          ,       3,      USER_DEFINED2
    15          ,       4,      USER_DEFINED3
    16          )       AS COLLAPSED_COL
    17  FROM            TEST_DATA
    18  CROSS JOIN      (SELECT ROWNUM RN FROM DUAL CONNECT BY LEVEL <= 4)
    19  /
           COLLAPSED_COL
                    1234
                    2424
                   44382
                   42488
                    5678
                   64635
                 4924929
                   88488
                    6789
                    8977
                    9449
                  888324
                     987
                  789534
                  242424
                     888
    16 rows selected.

  • Converting Column Header to Rows Value in SQL Query

    Dear Guys,find blew the table from A1_30 to YetToDue columns. I need from A1_30 to A356 columns convert into row values and that values column head name like Abstract. A1_30 A31_60 A61_90 A91_120 A121_180A181_365A365 BalArr NoOfLoanLoanOS YetToDue
    0 0 0 101 0 0 0 909 66730 909 3637
    0 40 0 0 0 0 0 1818 66681 1818 3637
    0 56 0 0 0 0 0 1818 70210 1818 5455
    0 0 66 0 0 0 0 909 73735 909 7273
    0 35 0 0 0 0 0 2727 73327 2727 7273
    0 0 66 0 0 0 0 909 73353 909 7273
    0 40 0 0 0 0 0 909 66778 909 3637
    0 40 0 0 0 0 0 1818 66744 1818 3637
    0 0 0 101 0 0 0 909 66787 909 3637
    0 40 0 0 0 0 0 1818 66671 1818 3637
    0 56 0 0 0 0 0 1818 70201 1818 5455
    0 56 0 0 0 0 0 1818 70204 1818 5455
    0 0 66 0 0 0 0 909 73331 909 7273
    0 40 0 0 0 0 0 1818 66726 1818 3637
    0 40 0 0 0 0 0 2727 66798 2727 3637
    0 40 0 0 0 0 0 909 66676 909 3637
    0 40 0 0 0 0 0 1818 66685 1818 3637
    0 56 0 0 0 0 0 1818 70209 1818 5455
    0 57 0 0 0 0 0 1818 70226 1818 5455
    0 35 0 0 0 0 0 2727 73762 2727 7273
    0 0 66 0 0 0 0 909 73333 909 7273
    0 40 0 0 0 0 0 1818 66759 1818 3637
    0 40 0 0 0 0 0 882 66597 882 8826
    0 40 0 0 0 0 0 2727 66789 2727 3637
    0 40 0 0 0 0 0 2646 66609 2646 8826
    0 40 0 0 0 0 0 2646 66641 2646 8826
    0 57 0 0 0 0 0 1818 70193 1818 5455
    0 56 0 0 0 0 0 1818 70202 1818 5455
    0 35 0 0 0 0 0 2727 73757 2727 7273
    0 0 66 0 0 0 0 909 73345 909
    7273
    I expecting the results:
    Abstract BalArr NoOfLoan LoanOS YetToDue
    A0_30 0 0 0 0
    A31_60 45261 1579445 45261 122852
    A61_90 4545 367097 4545 36365
    A91_120 1818 133517 1818 7274
    A121_180 0 0 0 0
    A181_365 0 0 0 0
    A365 0 0 0 0
    pls help I really appreciate ..

    Dear Partrck Hurst.I have facing struggle with my store procedure , It work very slow performance when i pass the entryPlease go through my store procedure and let me advice if i wrote the script wrongly .ALTER PROCEDURE [dbo].[MFDB_GenerateDCBCollection]
    @i_BranchId INT,
    @i_SHGId INT,
    @p_SHGMemberId INT,
    @i_LoanNumber INT,
    @i_DayOpenDate DATETIME,
    @o_ErrorStatus INT Output
    ) AS
    --WITH ENCRYPTION AS
    DECLARE @p_DayOpenDate AS DATETIME
    DECLARE @p_BranchId AS INT
    DECLARE @D_FromDate AS DATE
    DECLARE @D_ToDate AS DATE
    DECLARE @E_ToDate AS DATE
    DECLARE @p_RecordCounter AS INT
    DECLARE @p_RecordCount AS INT
    DECLARE @p_TempCollectionId AS INT
    DECLARE @p_TempStateId AS INT
    DECLARE @p_TempRegionId AS INT
    DECLARE @p_TempBranchId AS INT
    DECLARE @p_TempSHGId AS INT
    DECLARE @p_TempSHGName AS VARCHAR(75)
    DECLARE @p_TempSHGMemberId AS INT
    DECLARE @p_TempMemberId AS INT
    DECLARE @p_TempMemberName AS VARCHAR(75)
    DECLARE @p_TempVillageName AS VARCHAR(100)
    DECLARE @p_TempPanchayatName AS VARCHAR(100)
    DECLARE @p_TempPanchayatId AS INT
    DECLARE @p_TempVillageId AS INT
    DECLARE @p_TempInstNumber AS INT
    DECLARE @p_TempLoanNumber AS INT
    DECLARE @p_TempDisbursedDate AS DATE
    DECLARE @p_TempStatus AS INT
    DECLARE @p_TempLoanSchemeId AS INT
    DECLARE @p_TempLCategoryId AS INT
    DECLARE @p_TempLActivityId AS INT
    DECLARE @p_TempLActSpecId AS INT
    DECLARE @p_TempLoanAmount AS NUMERIC(18,2)
    DECLARE @p_TempApprovalStatus AS INT
    DECLARE @p_TempFundingAgencyId AS INT
    DECLARE @p_TempOpenBalPrin AS NUMERIC(18,2)
    DECLARE @p_TempOpenBalInt AS NUMERIC(18,2)
    DECLARE @p_TempStdPrin AS NUMERIC(18,2)
    DECLARE @p_TempStdInt AS NUMERIC(18,2)
    DECLARE @p_TempCollPrin AS NUMERIC(18,2)
    DECLARE @p_TempCollInt AS NUMERIC(18,2)
    DECLARE @p_TempAdvancePrin AS NUMERIC(18,2)
    DECLARE @p_TempAdvanceInt AS NUMERIC(18,2)
    DECLARE @p_TempArrearPrin AS NUMERIC(18,2)
    DECLARE @p_TempArrearInt AS NUMERIC(18,2)
    DECLARE @p_TempBalancePrin AS NUMERIC(18,2)
    DECLARE @p_TempBalanceInt AS NUMERIC(18,2)
    DECLARE @p_TempDemandDate AS DATE
    DECLARE @p_TempCollectionDate AS DATE
    DECLARE @p_TempLStatus AS INT
    DECLARE @p_TempLSourceId AS INT
    DECLARE @p_TempVoucherName AS VARCHAR(75)
    DECLARE @p_TempInsurance AS NUMERIC(18,2)
    DECLARE @p_TempUpFrontFess AS NUMERIC(18,2)
    DECLARE @p_TempDocumentFees AS NUMERIC(18,2)
    DECLARE @p_TotalInterest AS NUMERIC(18,2)
    DECLARE @i_Month AS INT = 1
    DECLARE @p_Year AS INT = 2015
    DECLARE @i_SHGMemberId AS INT
    BEGIN TRANSACTION DCBGenerated
    BEGIN
    Set @o_ErrorStatus = 0
    SELECT @D_FromDate = DATEADD(MONTH, @i_Month - 1, DATEADD(YEAR, @p_Year - 1900, 0)) --as [START DATE]
    SELECT @D_ToDate = DATEADD(MONTH, @i_Month, DATEADD(YEAR, @p_Year - 1900, -1)) --as [EMD DATE]
    SELECT @i_SHGMemberId = MFDB_SHGMemberId FROM MFDB_SHGMEMBER_MASTER WHERE MFDB_SHGId = @i_SHGId AND MFDB_MemberId = @p_SHGMemberId
    SELECT @p_TempVillageName = MFDB_VillageName,
    @p_TempVillageId = MFDB_VillageId ,
    @p_TempPanchayatId = MFDB_PanchayatId ,
    @p_TempPanchayatName = MFDB_PanchayatName
    FROM MFDB_SHG_MASTER WHERE MFDB_SHGId = @i_SHGId
    /* Drop and Create TempCollection Table. This table has all installments for a given member */
    CREATE TABLE #TEMPDCBCOLLECTION
    [MFDB_LedgerNumber] [int] IDENTITY(1,1) NOT NULL,
    [MFDB_StateId] [int] NOT NULL,
    [MFDB_RegionId] [int] NOT NULL,
    [MFDB_BranchId] [int] NOT NULL,
    [MFDB_SHGId] [int] NOT NULL,
    [MFDB_SHGName] [varchar](75) NOT NULL,
    [MFDB_ShgMemberId] [int] NOT NULL,
    [MFDB_MemberName] [varchar](50) NOT NULL,
    [MFDB_LoanNumber] [int] NOT NULL,
    [MFDB_LoanAmount] [int] NOT NULL
    ) ON [PRIMARY]
    /* Drop and Create TempCollection Table. This table has all installments for a given member */
    ;WITH CTE_1 AS
    SELECT CT.MFDB_StateId AS StateId,
    CT.MFDB_RegionId AS RegionId,
    CT.MFDB_BranchId AS BranchId,
    CT.MFDB_SHGId AS ShgId,
    SM.MFDB_SHGName AS ShgName,
    CT.MFDB_SHGMemberId AS SHGMemberId,
    SMM.MFDB_MemberName AS MemberName,
    CT.MFDB_LoanNumber AS LoanNumber,
    LM.MFDB_LoanAmount AS LoanAmount
    FROM dbo.MFDB_COLLECTION_TXN CT
    LEFT JOIN dbo.MFDB_COLLECTION_AUDIT CA
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_MemberId = CA.MFDB_MemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    INNER JOIN dbo.MFDB_SHG_MASTER SM
    On CT.MFDB_SHGId = SM.MFDB_SHGId
    INNER JOIN dbo.MFDB_SHGMEMBER_MASTER SMM
    On CT.MFDB_SHGId = SMM.MFDB_SHGId
    And CT.MFDB_SHGMemberId = SMM.MFDB_SHGMemberId
    INNER JOIN dbo.MFDB_LOANAPPLICATION_MASTER LM
    ON LM.MFDB_SHGId = CT.MFDB_SHGId
    AND LM.MFDB_ShgMemberId = CT.MFDB_ShgMemberId
    AND LM.MFDB_LoanNumber = CT.MFDB_LoanNumber
    Where DATEDIFF(DAY,MFDB_CollectionDate,@i_DayOpenDate) = 0
    And CT.MFDB_CollectionAmount > 0
    And CT.MFDB_CollApprovedBy IS NULL
    AND CT.MFDB_BranchId = @i_BranchId
    AND CT.MFDB_SHGId = @i_SHGId
    AND CT.MFDB_ShgMemberId = @i_SHGMemberId
    AND CT.MFDB_LoanNumber = @i_LoanNumber
    CTE_2 AS
    SELECT DISTINCT
    StateId,
    RegionId,
    BranchId,
    ShgId,
    ShgName,
    SHGMemberId,
    MemberName,
    LoanNumber,
    LoanAmount
    FROM CTE_1
    INSERT INTO #TEMPDCBCOLLECTION ([MFDB_StateId],[MFDB_RegionId],[MFDB_BranchId],[MFDB_SHGId],[MFDB_SHGName],[MFDB_ShgMemberId],[MFDB_MemberName],[MFDB_LoanNumber],[MFDB_LoanAmount])
    SELECT StateId,
    RegionId,
    BranchId,
    ShgId,
    ShgName,
    SHGMemberId,
    MemberName,
    LoanNumber,
    LoanAmount
    FROM CTE_2
    DECLARE DCBMonthCursor CURSOR FOR
    SELECT [MFDB_StateId],
    [MFDB_RegionId],
    [MFDB_BranchId],
    [MFDB_SHGId],
    [MFDB_SHGName],
    [MFDB_ShgMemberId],
    [MFDB_MemberName],
    [MFDB_LoanNumber],
    [MFDB_LoanAmount]
    FROM #TEMPDCBCOLLECTION
    OPEN DCBMonthCursor
    FETCH NEXT FROM DCBMonthCursor
    INTO @p_TempStateId ,
    @p_TempRegionId ,
    @p_TempBranchId ,
    @p_TempSHGId ,
    @p_TempSHGName ,
    @p_TempSHGMemberId ,
    @p_TempMemberName ,
    @p_TempLoanNumber ,
    @p_TempLoanAmount
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
    Set @p_TotalInterest = 0
    Select @p_TotalInterest = SUM(MFDB_StdInterest) From MFDB_LOAN_DISBURSEMENT Where MFDB_SHGId = @p_TempSHGId And MFDB_ShgMemberId = @p_TempSHGMemberId And MFDB_LoanNumber = @p_TempLoanNumber
    ;With
    CTE_1 AS
    SELECT LM.MFDB_StateId AS StateId ,
    LM.MFDB_RegionId AS RegionId,
    LM.MFDB_BranchId AS BranchId,
    LM.MFDB_SHGId AS SHGId,
    SM.MFDB_SHGName AS SHGName,
    LM.MFDB_ShgMemberId AS SHGMemId,
    LM.MFDB_MemberName AS MemberName,
    SM.MFDB_VillageId AS VillageId,
    LM.MFDB_LoanNumber AS LoanNo,
    LM.MFDB_LoanAmount AS LoanAmount,
    LM.MFDB_DisburseDate AS DisbursedDate,
    ISNULL((SELECT LD.MFDB_DemandDate
    FROM dbo.MFDB_LOAN_DISBURSEMENT LD
    Where LD.MFDB_SHGId = LM.MFDB_SHGId
    And LD.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    And LD.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,LD.MFDB_DemandDate,@i_DayOpenDate) = 0
    And LD.MFDB_ApprovalStatus = 1 ),NULL) AS DemandDate,
    ISNULL((SELECT TOP 1 CT.MFDB_CollectionDate
    FROM dbo.MFDB_COLLECTION_TXN CT
    Inner Join dbo.MFDB_COLLECTION_AUDIT CA
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CT.MFDB_SHGId = LM.MFDB_SHGId
    AND CT.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CT.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ORDER BY CA.MFDB_CollectionId DESC),NULL) AS CollectionDate,
    ISNULL((SELECT TOP 1 CA.MFDB_InstallmentNumber
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ORDER BY CA.MFDB_CollectionId DESC),
    ISNULL((SELECT LD.MFDB_InstallmentNumber
    FROM dbo.MFDB_LOAN_DISBURSEMENT LD
    Where LD.MFDB_SHGId = LM.MFDB_SHGId
    And LD.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    And LD.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,LD.MFDB_DemandDate,@i_DayOpenDate) = 0
    And LD.MFDB_ApprovalStatus = 1 ),0)) AS IntallNo,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_BalancePrincipal
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS ArrPrincipal,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_BalanceInterest
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS ArrInterest,
    0 AS CurrDemandPrin,
    0 AS CurrDemandInt,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedPrincipal,0) +
    ISNULL(CA.MFDB_AdvancePrincipal,0) +
    ISNULL(CA.MFDB_ArrearPrincipal,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ),0) AS CurrCollPri,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedInterest,0) +
    ISNULL(CA.MFDB_AdvanceInterest,0) +
    ISNULL(CA.MFDB_ArrearInterest,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) = 0
    ),0) AS CurrCollInt,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_AdvCBPrincipal
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS AdvOBPri,
    ISNULL(CAST((SELECT TOP 1 NR.MFDB_AdvCBInterest
    FROM dbo.MFDB_NEW_DCB_REPORT NR
    WHERE NR.MFDB_SHGId = LM.MFDB_SHGId
    AND NR.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND NR.MFDB_LoanNumber = LM.MFDB_LoanNumber
    ORDER BY NR.MFDB_LedgerNumber DESC) AS NUMERIC(18,0)),0) AS AdvOBInt,
    0 AS AdvCBPri,
    0 AS AdvCBInt,
    0 AS BalancePri,
    0 AS BalanceInt,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedPrincipal,0) +
    ISNULL(CA.MFDB_AdvancePrincipal,0) +
    ISNULL(CA.MFDB_ArrearPrincipal,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) >= 0
    ),0) AS OS_Pri,
    ISNULL((SELECT CAST(SUM(ISNULL(CA.MFDB_CollectedInterest,0) +
    ISNULL(CA.MFDB_AdvanceInterest,0) +
    ISNULL(CA.MFDB_ArrearInterest,0)) AS NUMERIC(18,0))
    FROM dbo.MFDB_COLLECTION_AUDIT CA
    Inner Join dbo.MFDB_COLLECTION_TXN CT
    On CT.MFDB_SHGId = CA.MFDB_SHGId
    And CT.MFDB_ShgMemberId = CA.MFDB_ShgMemberId
    And CT.MFDB_LoanNumber = CA.MFDB_LoanNumber
    And CT.MFDB_LSourceId = CA.MFDB_LSourceId
    And CT.MFDB_CollectionId = CA.MFDB_CollectionId
    WHERE CA.MFDB_SHGId = LM.MFDB_SHGId
    AND CA.MFDB_ShgMemberId = LM.MFDB_ShgMemberId
    AND CA.MFDB_LoanNumber = LM.MFDB_LoanNumber
    And DATEDIFF(DAY,CT.MFDB_CollectionDate,@i_DayOpenDate) >= 0
    ),0) AS OS_Int,
    0 AS RepaymentPercentage,
    LM.MFDB_LoanSchemeId AS LoanProduct,
    LM.MFDB_LActivityId AS LoanActivity,
    LM.MFDB_LActSpecId AS LoanSubActivity,
    LM.MFDB_FundingAgencyId AS FundAgencyId,
    LM.MFDB_LSourceId AS SourceId
    FROM dbo.MFDB_LOANAPPLICATION_MASTER LM
    Left Join dbo.MFDB_SHG_MASTER SM
    On SM.MFDB_ShgId = LM.MFDB_ShgId
    WHERE LM.MFDB_ApprovalStatus= 3
    AND LM.MFDB_DisburseDate IS NOT NULL
    AND LM.MFDB_StateId = @p_TempStateId
    AND LM.MFDB_RegionId = @p_TempRegionId
    AND LM.MFDB_BranchId = @p_TempBranchId
    AND LM.MFDB_SHGId = @p_TempSHGId
    AND LM.MFDB_ShgMemberId = @p_TempSHGMemberId
    AND LM.MFDB_LoanNumber = @p_TempLoanNumber
    CTE_2 AS
    SELECT StateId, RegionId, BranchId, SHGId, SHGName, SHGMemId, MemberName, VillageId , LoanNo, LoanAmount, DisbursedDate,DemandDate, CollectionDate, IntallNo,
    ArrPrincipal,
    ArrInterest,
    CurrDemandPrin,
    CurrDemandInt,
    ISNULL(ISNULL(ArrPrincipal,0) + ISNULL(CurrDemandPrin,0),0) AS TotDemandPri,
    ISNULL(ISNULL(ArrInterest,0) + ISNULL(CurrDemandInt,0),0) AS TotDemandInt,
    AdvOBPri,
    AdvOBInt,
    CurrCollPri,
    CurrCollInt,
    AdvCBPri,
    AdvCBInt,
    BalancePri,
    BalanceInt,
    ISNULL(ISNULL(LoanAmount,0) - ISNULL(OS_Pri,0),0) AS OS_Pri,
    ISNULL(ISNULL(@p_TotalInterest,0) - ISNULL(OS_Int,0),0) OS_Int,
    CONVERT(INT,RepaymentPercentage) AS RepaymentPercentage,
    LoanProduct,
    LoanActivity,
    LoanSubActivity,
    FundAgencyId,
    SourceId
    FROM CTE_1
    CTE_3 AS
    SELECT StateId, RegionId, BranchId, SHGId, SHGName, SHGMemId, MemberName, VillageId , LoanNo, LoanAmount, DisbursedDate,DemandDate, CollectionDate, IntallNo,
    ArrPrincipal,
    ArrInterest,
    CurrDemandPrin,
    CurrDemandInt,
    TotDemandPri,
    TotDemandInt,
    CASE WHEN AdvOBPri < 0 THEN AdvOBPri * -1 ELSE AdvOBPri END AS AdvOBPri,
    CASE WHEN AdvOBInt < 0 THEN AdvOBInt * -1 ELSE AdvOBInt END AS AdvOBInt,
    CurrCollPri,
    CurrCollInt,
    CASE WHEN ISNULL(TotDemandPri,0) = 0 THEN ISNULL((CurrCollPri + AdvOBPri),0)
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) > ISNULL(TotDemandPri,0) THEN ISNULL(ISNULL(CurrCollPri + AdvOBPri,0) - ISNULL(TotDemandPri,0),0)
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) < ISNULL(TotDemandPri,0) THEN 0
    WHEN ISNULL(CurrCollPri + AdvOBPri,0) = ISNULL(TotDemandPri,0) THEN 0
    ELSE 0 END AS AdvCBPri,
    CASE WHEN ISNULL(TotDemandInt,0) = 0 THEN ISNULL((CurrCollInt + AdvOBInt),0)
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) > ISNULL(TotDemandInt,0) THEN ISNULL(ISNULL(CurrCollInt + AdvOBInt,0) - ISNULL(TotDemandInt,0),0)
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) < ISNULL(TotDemandInt,0) THEN 0
    WHEN ISNULL(CurrCollInt + AdvOBInt,0) = ISNULL(TotDemandInt,0) THEN 0
    ELSE 0 END AS AdvCBInt,
    0 AS BalancePri,
    0 AS BalanceInt,
    OS_Pri,
    OS_Int,
    0 AS Repayment,
    LoanProduct,
    LoanActivity,
    LoanSubActivity,
    FundAgencyId,
    SourceId,
    CONVERT(CHAR(3), @i_DayOpenDate, 0) + ' - ' + RIGHT(CONVERT(CHAR(4), YEAR(@i_DayOpenDate)),2) AS Months
    FROM CTE_2
    INSERT INTO dbo.MFDB_NEW_DCB_REPORT
    ( [MFDB_TxnDate]
    ,[MFDB_StateId]
    ,[MFDB_RegionId]
    ,[MFDB_BranchId]
    ,[MFDB_SHGId]
    ,[MFDB_SHGName]
    ,[MFDB_ShgMemberId]
    ,[MFDB_MemberName]
    ,[MFDB_VillageId]
    ,[MFDB_LoanNumber]
    ,[MFDB_LoanAmount]
    ,[MFDB_DisbursedDate]
    ,[MFDB_DemandDate]
    ,[MFDB_CollectionDate]
    ,[MFDB_InstallmentNumber]
    ,[MFDB_ArrearPrincipal]
    ,[MFDB_ArrearInterest]
    ,[MFDB_DemandPrincipal]
    ,[MFDB_DemandInterest]
    ,[MFDB_TotDemandPrincipal]
    ,[MFDB_TotDemandInterest]
    ,[MFDB_AdvOBPrincipal]
    ,[MFDB_AdvOBInterest]
    ,[MFDB_CollectedPrincipal]
    ,[MFDB_CollectedInterest]
    ,[MFDB_AdvCBPrincipal]
    ,[MFDB_AdvCBInterest]
    ,[MFDB_BalancePrincipal]
    ,[MFDB_BalanceInterest]
    ,[MFDB_OS_Pri]
    ,[MFDB_OS_Int]
    ,[MFDB_RepaymentPercentage]
    ,[MFDB_LoanSchemeId]
    ,[MFDB_LActivityId]
    ,[MFDB_LActSpecId]
    ,[MFDB_FundAgencyId]
    ,[MFDB_LSourceId]
    ,[MFDB_Months]
    ,[MFDB_PanchayatId]
    ,[MFDB_PanchayatName]
    ,[MFDB_VillageName]
    SELECT @i_DayOpenDate ,StateId, RegionId, BranchId, SHGId, SHGName, SHGMemId, MemberName, VillageId , LoanNo, LoanAmount, DisbursedDate,DemandDate,CollectionDate,IntallNo,
    ArrPrincipal,ArrInterest,CurrDemandPrin,CurrDemandInt,TotDemandPri,TotDemandInt,AdvOBPri,AdvOBInt,CurrCollPri,CurrCollInt,
    CASE WHEN AdvCBPri < 0 THEN 0 ELSE AdvCBPri END,
    CASE WHEN AdvCBInt < 0 THEN 0 ELSE AdvCBInt END,
    CASE WHEN ISNULL(TotDemandPri,0) = 0 THEN 0
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) > ISNULL(TotDemandPri,0) THEN 0
    WHEN ISNULL(TotDemandPri,0) > 0 AND ISNULL(CurrCollPri + AdvOBPri,0) < ISNULL(TotDemandPri,0) THEN ABS(ISNULL(ISNULL(CurrCollPri + AdvOBPri,0) - ISNULL(TotDemandPri,0),0) * -1)
    WHEN ISNULL(CurrCollPri + AdvOBPri,0) = ISNULL(TotDemandPri,0) THEN 0
    ELSE 0 END AS BalancePri,
    CASE WHEN ISNULL(TotDemandInt,0) = 0 THEN 0
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) > ISNULL(TotDemandInt,0) THEN 0
    WHEN ISNULL(TotDemandInt,0) > 0 AND ISNULL(CurrCollInt + AdvOBInt,0) < ISNULL(TotDemandInt,0) THEN ABS(ISNULL(ISNULL(CurrCollInt + AdvOBInt,0) - ISNULL(TotDemandInt,0),0) * -1)
    WHEN ISNULL(CurrCollInt + AdvOBInt,0) = ISNULL(TotDemandInt,0) THEN 0
    ELSE 0 END AS BalanceInt,
    OS_Pri,
    OS_Int,
    0 AS Repayment,
    LoanProduct,LoanActivity,LoanSubActivity,FundAgencyId,SourceId,Months,@p_TempPanchayatId,@p_TempPanchayatName,@p_TempVillageName
    FROM CTE_3
    If @@Error != 0
    Begin
    Set @o_ErrorStatus = 1
    ROLLBACK TRANSACTION DCBGenerated
    RETURN
    End
    FETCH NEXT FROM DCBMonthCursor
    INTO @p_TempStateId ,
    @p_TempRegionId ,
    @p_TempBranchId ,
    @p_TempSHGId ,
    @p_TempSHGName ,
    @p_TempSHGMemberId ,
    @p_TempMemberName ,
    @p_TempLoanNumber ,
    @p_TempLoanAmount
    END
    CLOSE DCBMonthCursor
    DEALLOCATE DCBMonthCursor
    DELETE FROM #TEMPDCBCOLLECTION
    If @@Error != 0
    Begin
    Set @o_ErrorStatus = 1
    ROLLBACK TRANSACTION DCBGenerated
    RETURN
    End
    END
    COMMIT TRANSACTION DCBGenerated

  • Converting column data into rows in oracle 10g

    sample data:
    PATID NA2     NA3     NA4     
    1     3     4     5     
    1     34     45     56     
    1     134     245     356     
    2     134     245     356     
    2     334     275     56     
    2     4     275     56     
    2     4     5     56     
    how to display the above data like
    PATID NA2 NA3 NA4
    1 ID1 ID2 ID3 ID4 ID1 ID2 ID3 ID4 ID1 ID2 ID3 ID4
    3 34 134 4 45 245 5 56 356
    2 134 134 4 4 245 275 275 5 356 56 56 56

    Many examples are here:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    (and you can do a search on this forum as well to find more)
    edit
    Your sample data is not very clear, by the way.
    Please post a CREATE TABLE and some INSERT statements, just enough to put up the testcase.
    Use the tag before and after posting examples, so formatting will be maintained.
    See the [FAQ|http://forums.oracle.com/forums/help.jspa] for more information regarding tags (scroll a bit down)...
    Edited by: hoek on Jan 26, 2010 5:23 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Converting Column to Rows

    Hello,
    I am trying to build and SQL to convert columns from multiple rows to the all rows - see below test data and result expected:
    CREATE TABLE XX_TEST(NAME VARCHAR2(10),A1 VARCHAR2(10),A2 VARCHAR2(10), A3 VARCHAR2(10),A4 VARCHAR2(10),A5 VARCHAR2(10));
    INSERT INTO XX_TEST VALUES('LIST','A','B','C','D','E');
    INSERT INTO XX_TEST VALUES('L1','1',NULL,'3',NULL,NULL);
    INSERT INTO XX_TEST VALUES('L2','1','5','4',NULL,NULL);
    COMMIT
    SELECT * FROM XX_TEST;
    Result expected:
    NAME is Column from table XX_TEST but COLUMN and VALUE are the columns converted to rows-
    NAME COLUMN VALUE
    L1 A1 1
    L1 A2 NULL
    L1 A3 3
    L1 A4 NULL
    L1 A5 NULL
    L2 A1 1
    L2 A2 5
    L2 A3 4
    L2 A4 NULL
    L2 A5 NULL
    Thanks
    BS

    Hi,
    Thanks for posting the sample data in such a useful form!
    Whenever you post a question, you should always say what version of Oracle you're using, too.
    Displaying multiple columns from one row as one column on multiple rows is called Unpivoting .
    In Oracle 11, you can use the SELECT ... UNPIVOT feature to do that.
    In any version of Oracle, you can cross-join your table to a Counter that has as many rows as your original table has columns to be unpivoted.
    In this problem, we need a self-join of the unpivoted data, to join the rows with name='LIST' to every other row.
    WITH     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL     <= 5
    ,     unpivoted_xx_test     AS
         SELECT     x.name
         ,     'A' || c.n     AS col
         ,     CASE  c.n
                   WHEN 1     THEN x.a1
                   WHEN 2     THEN x.a2
                   WHEN 3     THEN x.a3
                   WHEN 4     THEN x.a4
                   WHEN 5     THEN x.a5
              END          AS val
         FROM          cntr     c
         CROSS JOIN     xx_test     x
    SELECT       u.name
    ,       u.col
    ,       l.val          AS val1
    ,       u.val          AS val2
    FROM       unpivoted_xx_test     l
    JOIN       unpivoted_xx_test     u  ON     l.col     = u.col
    WHERE       l.name     =  'LIST'
    AND       u.name     != 'LIST'
    ORDER BY  name
    ,       col
    ;Output:
    NAME       COL VAL1       VAL2
    L1         A1  A          1
    L1         A2  B
    L1         A3  C          3
    L1         A4  D
    L1         A5  E
    L2         A1  A          1
    L2         A2  B          5
    L2         A3  C          4
    L2         A4  D
    L2         A5  EThe query above uses some features that were new in Oracle 9, but the basic strategy will work in earlier versions.
    If your columns don't have such regular names (A1, A2, A3, ...) then you can use another CASE expression to derive unpivoted_xx_test.col.

  • How to convert columns into rows using  transpose function

    Hi
    anybody tell me how to convert columns values into rows using transpose function.

    Since BluShadow went to all the trouble to put it together, someone should use it.
    See the post titled How do I convert rows to columns? here SQL and PL/SQL FAQ
    John

  • Need to Convert Comma separated data in a column into individual rows from

    Hi,
    I need to Convert Comma separated data in a column into individual rows from a table.
    Eg: JOB1 SMITH,ALLEN,WARD,JONES
    OUTPUT required ;-
    JOB1 SMITH
    JOB1 ALLEN
    JOB1 WARD
    JOB1 JONES
    Got a solution using Oracle provided regexp_substr function, which comes handy for this scenario.
    But I need to use a database independent solution
    Thanks in advance for your valuable inputs.
    George

    Go for ETL solution. There are couple of ways to implement.
    If helps mark

  • Convert columns to row equivalent to stragg function in oracle sql

    Hi,
    Sorry i forgot my Oracle version :
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 64-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - ProductionI searched in google but i didn't found the solution.
    I looking for a function in discoverer equivalent to stragg sql function.
    Note : stragg function convert columns to rows.
    Thanks
    SELECT   deptno, stragg ('-' || ename)
        FROM emp_test
    GROUP BY deptno;
        DEPTNO STRAGG_STR                                                 
            10 -CLARK-KING-MILLER                                         
            20 -SMITH-FORD-ADAMS-SCOTT-JONES                              
            30 -ALLEN-BLAKE-MARTIN-TURNER-JAMES-WARD                      
    3 rows selected.Edited by: Salim Chelabi on 2010-01-29 08:32

    Hi again,
    *1- I created  my function in my schema.*
    CREATE OR REPLACE TYPE t_string_agg AS OBJECT
      g_string  VARCHAR2(32767),
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
         RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER
    SHOW ERRORS
    CREATE OR REPLACE TYPE BODY t_string_agg IS
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER IS
      BEGIN
        sctx := t_string_agg(NULL);
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := self.g_string || ',' || value;
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER IS
      BEGIN
        returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
        RETURN ODCIConst.Success;
      END;
    END;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
    RETURN VARCHAR2
    PARALLEL_ENABLE AGGREGATE USING t_string_agg;
    SHOW ERRORS
    *2- I ran my query in my schema with sqlplus.*
    SELECT deptno,ename,sal, string_agg(ename)over(partition by deptno) AS employees
    FROM   emp_test
    order by deptno;
        DEPTNO ENAME             SAL EMPLOYEES                                        
            10 CLARK            2450 CLARK,KING,MILLER                                
            10 KING             5000 CLARK,KING,MILLER                                
            10 MILLER           1300 CLARK,KING,MILLER                                
            20 JONES            2975 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 FORD             3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 ADAMS            1100 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SMITH             800 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SCOTT            3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            30 WARD             1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 TURNER           1500 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 ALLEN            1600 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 JAMES             950 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 BLAKE            2850 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 MARTIN           1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
    14 rows selected.
    *3- I import this function in discoverer administration*
    4- My problem :When i use the function string_agg(ename)over(partition by deptno) in discover deskto i got the error you can't use over in this place.
    Any ideas.
    Thank in advance.
    Regards Salim.

  • To convert columns into row

    Hi All,
    I need help in building view which actually can show columns data as row.
    e.g.
    row is as follows
    Name Age Salary
    ABC 25 10000
    BBC 28 12000
    The above tables data I want to get as
    Name ABC BBC
    Age 25 28
    Salary 10000 12000
    Thanks in advance.

    Even if I don't really understand such requirement, I wrote some times ago such function to play around that :
    Re: Converting Columns into rows
    Nicolas.

  • Converting columns to row

    Hi,
    I have 6 columns and 4 rows and i want to convert it into 6 rows and 4 columns and want to display in table control.
    plz help me in this ....

    Hi Kinjal,
       Question is not clear. You want to change the internal table values with 6 columns & 4 rows to 4 columns & 6 rows?
    If my understanding is correct, check the bleow logic:
    loop at itab1.
    case sy-tabix.
      when 1.
       itab2-c1 = itab1-c1.
       append itab2.
       itab2-c1 = itab1-c2.
       append itab2.
       itab2-c1 = itab1-c3.
       append itab2.
       itab2-c1 = itab1-c4.
       append itab2.
       itab2-c1 = itab1-c5.
       append itab2.
       itab2-c1 = itab1-c6.
       append itab2.
    when 2.
      itab2-c2 = itab1-c1.
      modify itab2 transporting c2 index 1.
      itab2-c2 = itab1-c2.
      modify itab2 transporting c2 index 2.
      itab2-c2 = itab1-c3.
      modify itab2 transporting c2 index 3.
      itab2-c2 = itab1-c4.
      modify itab2 transporting c2 index 4.
      itab2-c2 = itab1-c5.
      modify itab2 transporting c2 index 5.
      itab2-c2 = itab1-c6.
      modify itab2 transporting c2 index 6.
    when 3.
       itab2-c3 = itab1-c1.
      modify itab2 transporting c3 index 1.
    when 4.
       itab2-c4 = itab1-c1.
      modify itab2 transporting c4 index 1.
    Endloop.
    Finally you will get 6 rows with 4 coulmns.

  • How to convert single column into single row

    I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
    emp_id
    100
    101
    102
    102
    103
    200
    I need output like 100,101,102,103,104.........200.

    I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
    with emp as (
                 select  level emp_id
                   from  dual
                   connect by level <= 5
    select  *
      from  emp
      pivot(
            max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
       EMP_ID1    EMP_ID2    EMP_ID3    EMP_ID4    EMP_ID5
             1          2          3          4          5
    SQL>
    SY.

  • Converting key figures from rows to column using DSO and start routine

    Hi SDNer:
    I need some help to convert key figures from rows to column.
    The source is DSO 1 and I am thinking about writing ABAP in the start routine to do the conversion. The target is DSO2.
    Below is the  more detail information with example. Basically, for each record in DSO 1 I need to create 3 records (because there are 3 KF's) and output to DSO2.
    I would really appreciate some help on this.Thank you.
    Tony
    DSO 1 data format (SOURCE)
    Period   ID   KF1  KF2  KF3
    200702 100  300  200   750
    Output to DSO 2 (TARGET)
    Period   ID    KF  LABEL
    200702 100  300  KF1
    200702 100  200  KF2
    200702 100  750  KF3

    This is the code in BI 7.0.
    u need to put a field "Label" in DSO1. u dont need to populate this in DSO1 but it helps the code to populate the field in DSO2.
    DATA: wa_result TYPE _ty_s_sc_1,
    t_result TYPE STANDARD TABLE OF _ty_s_sc_1.
    DATA:counter(2) TYPE n.
    LOOP AT SOURCE_PACKAGE INTO wa_result.
    counter =0.
    while counter < 3 .
    wa_result- Period = wa_result-Period.
    wa_result- ID = wa_result-ID.
    if counter  = 0.
    wa_result- KF1 = wa_result-KF1.
    wa_result- Label = 'KF1'.
    elseif counter = 1.
    wa_result- KF1 = wa_result-KF2.
    wa_result- Label = 'KF2'.
    else.
    wa_result- KF1 = wa_result-KF3.
    wa_result- Label = 'KF3'.
    endif.
    APPEND wa_result TO t_result.
    counter = counter+1.
    endwhile.
    endloop.
    CLEAR: SOURCE_PACKAGE,wa_result.
    LOOP AT t_result INTO wa_result.
    APPEND wa_result TO SOURCE_PACKAGE.
    ENDLOOP.

  • Convert column values into a row with a delimiter

    Hi Gurus,
    This may be a trivial question to you. I have an internal table itab with a column called plant, internal table has 'n' records, by the end of loop, I need to convert the column into a row delimited by comma into one row (one field). This needs to be dynamic without hard-coding.
    Plant
    1000
    2000
    3000
    4000
    5000 ....
    n....
    Expected result of the field:
    field1 value: 1000,2000,3000,4000,5000,...n
    Let's set a limit to the field say it can hold upto 500 chars.
    Thanks,
    GP.

    Hi,
    I've already tried this:
      ELSEIF <fs_dms_cv>-zca_cv_attr_ind = c_multiple.
      w_plant = <fs_plant_ele>-werks.
      concatenate w_string w_plant
                    into w_string separated by c_delimiter.
          IF w_end_fl = c_on.
          w_tabname = <fs_dms_cv>-dbtabname.
           ASSIGN (w_tabname) TO <fs_tabname>.
            IF sy-subrc = 0.
             ASSIGN COMPONENT <fs_dms_cv>-name_komp OF 
                STRUCTURE <fs_tabname> TO <fs_destination>.
                        IF sy-subrc = 0.
                          <fs_destination> = w_string.
                        ENDIF.
            ENDIF.
    There are 2 issues here: One is that after first plant there will be two commas inserted, after that it's consistent. Secondly the key word concatenate is against our code standards.
    Please let me know if there is any other way of doing this.
    Thanks.

  • Is there a way to convert 8 Rows by 2 Columns to 2 Rows by 8 Columns?

    I have tried but came to an stop...
    How do I convert 8 Rows by 2 Columns to 2 Rows by 8 Columns?
    as shown in the vi attached
    Thank you very much...
    Solved!
    Go to Solution.
    Attachments:
    Eight Rows Two Col convert to two Rows Eight Col.vi ‏8 KB

    JohnMc19 wrote:
    Hi Diego2000,
    Trying using the Transpose 2D array function found in the Array functions palette, think it is what you are asking for.
    Regards,
    No, for the required transformation reshape array is required, not transpose.
    Compare:
    Andrey.

Maybe you are looking for