locked
Datable Same Multi column Value into Single Column for inserting into Database (Denormalized source data to insert into normalized data ) RRS feed

  • Question

  • User-985386616 posted

    Hi All, 

    stuck in this from last two days but didnt find any solution , so please suggest me to proceed further, below is the situation or case.

    1) datatable returns data  having column like below 

    M_ECN M_NAME M_EMAIL B_ECN B_NAME B_EMAIL G_ECN G_NAME G_EMAIL
    1 ASDAS ASAS 56 ASDASD ASDASD 123 DSFSDF DFSDF
    2 ASDAS ASAS 45 ASDASD ASDASD 123 SDFSDF SDF
    3 ASDAS ASAS 45 ASDASD ASDASD 123 SDFSDF SDF
    4 ASDAS ASAS 45 ASDASD ASDASD 123 SDFSDF SDF
    5 ASDAS ASAS 89 ASDASD ASDASD 123 SDFSDF SDF

    i want datatable structure like below , want all ecn contain column in one column called 'ECN' , all Name Contains column in  NAME, all email contain column in EMAIL

    ECN NAME EMAIL
    1 ASDAS ASAS
    2 ASDAS ASAS
    3 ASDAS ASAS
    4 ASDAS ASAS
    5 ASDAS ASAS
    56 ASDASD ASDASD
    45 ASDASD ASDASD
    45 ASDASD ASDASD
    45 ASDASD ASDASD
    89 ASDASD ASDASD
    123 DSFSDF DFSDF
    123 SDFSDF SDF
    123 SDFSDF SDF
    123 SDFSDF SDF
    123 SDFSDF SDF

    now i want to insert values is database employee master which has column like using procedure parameters

    Create Procedure Insertintoempl

    (

    @ecn int,

    @name varchar(50),

    @email varchar(50)

    )

    as

    begin 

    insert into tblempl(ecn,name,email)

    values

    (@ecn,@name,@email)

    end

    Thursday, February 23, 2017 6:31 AM

All replies

  • User-832373396 posted

    Hi 7666974950,

    So your table structure is like

    M_ECN M_NAME M_EMAIL B_ECN

    Now you need to display it like this

    ECN NAME EMAIL

    if so, please refer to code below, and it works.

    select strBookTypeId as IID ,bookmasterId as y from BookMaster
    UNION ALL
    select bookmasterId as IID ,strBookTypeId as y from BookMaster

    Result:

    IID y

    4 1
    5 2
    6 3
    7 4
    1 4
    2 5
    3 6
    4 7

    Best regards,

    Jolie

    Friday, February 24, 2017 7:56 AM