Skip to main content
ashutoshg0001
September 15, 2021
Question

How can i Insert a row between two rows of cdt ?

  • September 15, 2021
  • 5 replies
  • 1 view

I have a table as follow:

                       sno         department

                        1             CS

                        2             ME

                        3             EI

             I want the output after inserting a row between sno 1 and 2 as 

 

                       sno         department

                        1             CS

                        2             IT

                        3             ME

                        4             EI

How can i do that?

    5 replies

    stefanhelzle0001
    Brainy
    September 15, 2021

    Is this a database table? Do you need the renumbering?

    ashutoshg0001
    September 15, 2021

    yes 

    in cdt i want to apply this

    stefanhelzle0001
    Brainy
    September 15, 2021

    a!localVariables(
      local!values: {
        {sno: 1, department: "CS"},
        {sno: 2, department: "ME"},
        {sno: 3, department: "EI"}
      },
      a!forEach(
        items: insert(
          local!values,
          {sno: 42, department: "IT"},
          2
        ),
        expression: a!update(
          data: fv!item,
          index: "sno",
          value: fv!index
        )
      )
    )