title: How to insert table valued parameters into Sql Azure from Node?
body: <p>I'm working on an application that inserts data in bulk and in order to reduce the number of queries I wanted to use Table Valued parameters.</p>
  
  <p>Example:</p>
  
  <pre><code>var sql = require('node-sqlserver');
  
  var connectionString = 'Driver={SQL Server Native Client 11.0};server=tcp:serverName.database.windows.net,1433;UID=user@serverName;PWD=password;Database={databaseName};Encrypt=yes;Connection Timeout=30;';
  
  sql.open(connectionString, function(err, conn) {
      if(err) {
          return console.error('could not connect to sql', err);
      }
  
      var tableValuedObject = ???;
  
      var query = 'usp_InsertSomeTable ?';
  
      conn.query(query, tableValuedObject, function(err, result) {
          if(err) {
              return console.error('error running insert', err);
          }
      });
  });
  </code></pre>
  
  <p>Where  <code>usp_InsertSomeTable</code> is defined as</p>
  
  <pre><code>CREATE PROCEDURE usp_InsertSomeTable
      @TVP SomeTableType READONLY
  AS
  BEGIN
      SET NOCOUNT ON;
      INSERT INTO SomeTable (Data) SELECT Data FROM @TVP;
  END
  </code></pre>
  
  <p>I have my table valued object defined as</p>
  
  <pre><code>CREATE TYPE SomeTableType AS TABLE
  (
       Data VARCHAR(50)
  );
  </code></pre>
  
  <p>What structure should the JavaScript object have or has that not been implemented in the <a href="https://github.com/WindowsAzure/node-sqlserver" rel="nofollow">Node-SqlServer</a> project?</p>
  
  <p>Edit 1:</p>
  
  <p>using <code>var tableValuedObject = { Data: 'Hello World' };</code> produces an error:</p>
  
  <pre><code>node-sqlserver\lib\sql.js:3254: Uncaught Error: [msnodesql] Invalid parameter(s) passed to function query or queryRaw.
  </code></pre>
  
  <p>Edit 2:</p>
  
  <p>using <code>var tableValuedObject = [{ Data: 'Hello World'}];</code> produces and error:</p>
  
  <pre><code>error running query { [Error: IMNOD: [msnodesql] Parameter 1: Invalid parameter type] sqlstate: 'IMNOD', code: -1 }
  </code></pre>