title: How to call the parameter of that stored Type and procedure in nodejs?
body: <p>I'm using postman to insert or update a giving array with nodejs into SQL Server database table. I'm trying to insert 'user or benutzer' if the id not exist and to update if id exist.</p>
  <p>That's how I create my database table:</p>
  <pre><code>create Table benutzer (
      id int primary key not null,
      firstName nvarchar(200) not null,
      lastname nvarchar(200) not null,
      active bit not null
  )
  </code></pre>
  <p>Here is my stored Procedure in SQL Server:</p>
  <pre><code>USE benutzerDb;
  GO
  
  CREATE TYPE BenutzerList AS TABLE (
      [b_id] INT,
      b_firstName NVARCHAR(200),
      b_lastName NVARCHAR(200),
      b_active bit
  );
  GO
  
  CREATE PROC updateBenutzer (@benutzerList BenutzerList READONLY)
  
  AS
  
  BEGIN
  
      MERGE benutzer AS ben
  
          USING @benutzerList AS blist
  
      ON ben.id = blist.[b_id]
  
      WHEN MATCHED THEN
  
          UPDATE SET 
  
          ben.firstName = blist.b_firstName,
          ben.lastName = blist.b_lastName,
          ben.active = blist.b_active
  
      WHEN NOT MATCHED THEN
  
          INSERT (id,firstName,lastName,active)
  
          VALUES (blist.b_id, blist.b_firstName, blist.b_lastName, blist.b_active);
  
      select * from @benutzerList
  
  END
  
  GO
  </code></pre>
  <p>-&gt;and hier how called in SqlServer and it's work perfekt:</p>
  <pre><code>use benutzerDb
  
  go
  
  DECLARE @benutzerList BenutzerList
  
  INSERT INTO @benutzerList VALUES(1,'Max','Müller',1),(15,'Ben','Kane',1)
  
  EXEC updateBenutzer @benutzerList
  
  SELECT * FROM benutzer
  </code></pre>
  <p>-&gt; and hier ist my function:</p>
  <pre><code>//function to add or update benutzer:
  
  async  function  addBenutzer() {
  
    try {
  
    const benutzerTable = new sql.Table();
  
    benutzerTable.columns.add('b_id', sql.Int);
  
    benutzerTable.columns.add('b_firstName', sql.NVarChar(200));
  
    benutzerTable.columns.add('b_lastName', sql.NVarChar(200));
  
    benutzerTable.columns.add('b_active', sql.Bit);
  
    const BenutzerList = req.body;
  
    BenutzerList.forEach(benutzer=&gt; {
  
      benutzerTable.rows.add(
  
        benutzer.b_id,
        benutzer.b_firstName,
        benutzer.b_lastName,
        benutzer.b_active
      )
    });
  
      let  pool = await  sql.connect(config);
  
      let  addBenutzer = await  pool.request()
  
      .input('benutzerList', benutzerTable)
  
      .execute(&quot;updateBenutzer&quot;);
  
      return  addBenutzer.recordsets;
  
    }
    catch (error) {
  
      console.log(error);
  
    }
  
  }
  
  router.route('/addBenutzer').post((request, response) =&gt; {
  
      let Daten = JSON.stringify(request.body);
  
      benutzerController.addBenutzer(Daten).then(result =&gt; {
  
          response.status(201).json(result);
  
      });
  
  })
  </code></pre>
  <p>-&gt; hier is the array what i'm giving in postman:</p>
  <pre><code>[
  
      {
          &quot;id&quot;: 1,
  
          &quot;firstName&quot;: &quot;Max&quot;,
  
          &quot;lastName&quot;: &quot;Müller&quot;,
  
          &quot;active&quot;: true
      },
  
      {
          &quot;id&quot;: 15,
  
          &quot;firstName&quot;: &quot;Ben&quot;,
  
          &quot;lastName&quot;: &quot;Kane&quot;,
  
          &quot;active&quot;: true
      }
  
  ]
  </code></pre>
  <p>It supose to update id 1 and insert id 15 but unfortunatly doesn't work, i will be appreciate for your help.</p>