question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use TVP as query input

See original GitHub issue

Providing Table Value Parameter as input to query fails on sp_executesql

Expected behaviour:

The query to execute successfully and give the result of

Actual behaviour:

The query fails to execute due to an issue with sp_executesql

Example that works in raw tsql

CREATE TYPE MyAwesomeType AS TABLE (storeNbr INT);

DECLARE @tvp StoreNumberTableType
INSERT INTO @tvp
VALUES (1), (2)

exec sp_executesql N'SELECT * FROM @tvp', N'@tvp MyAwesomeType readonly', @tvp

Translated example that fails in node-mssql

const t = new sql.Table('MyAwesomeType');

t.columns.add('storeNbr', sql.Int);
t.rows.add(1);
t.rows.add(2);

const req = connection.request();

req.input('tvp', t);
return req.query(`SELECT * from @tvp`);

Configuration:

// paste relevant config here

Software versions

  • NodeJS: 12.13.1
  • node-mssql: 6.2.1
  • SQL Server: Enterprise 2017

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
CDoughty08commented, Oct 2, 2020

@dhensby Looks like this is an issue with the way the underlying tediousjs library handles executing raw queries. Will close this issue and continue looking into this issue at the tedious layer. Will link the PR here, if I am able to figure out an acceptable fix.

1reaction
CDoughty08commented, Oct 1, 2020

I will look into it and see if I can figure it out to submit a PR. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use Table-Valued Parameter (TVP) in query (node ...
I am attempting to export some data from SQL, store it and later compare that data to the result of the same query....
Read more >
Not able to pass TVP as an input parameter to a Stored ...
I am trying to call a stored procedure which takes TVP(Table Valued parameter) as input parameter. const Sequelize = require('sequelize'); const ...
Read more >
TVP Performance with high volume... - MSDN - Microsoft
I have .NET application that passes parameters to a stored procedure. One of the parameters is a table valued parameter(TVP) which is with ......
Read more >
Table-Valued Parameters in SQL Server - SQLShack
Table-Valued Parameters aka TVPs are commonly used to pass a table as a parameter into stored procedures or functions. They are helpful in...
Read more >
Using Table-Valued Parameters in SQL Server and .NET
Let's first look at how to use TVPs in T‑SQL without involving a client. To be able to declare a TVP, you first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found