Skip to content

Unable to use TVP as query input  #1085

@CDoughty08

Description

@CDoughty08

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions