Table Valued Parameter helps us to pass multiple rows of data from a client application to SQL Server without multiple round trips. We can pass multiple rows to a stored procedure using a Table Valued Parameter.
This SQL query shows how to search in a collection of data returned by a stored procedure using table valued parameters.
Create a table and add some data to it. If you've your own table, use that.
- CREATE TABLE usertable
- (
- userid INT PRIMARY KEY,
- username VARCHAR(30)
- )
Create a table valued type
- CREATE TYPE username AS TABLE
- (
- user_name VARCHAR(30)
- )
Create a stored procedure.
- create proc search
- @user username readonly
- as
- begin
- select * from @user where username in(select username from usertable)
- end
Now you can use this procedure in your C# code when you want to filter a users list that you have in a datatable and need to get all users who are in user table.
Learn more here, Table Valued Parameters In SQL Server

Pankajkumar PatelPosted Aug 26, 2019, 11:54 PM
Nice article
Pankaj PandeyPosted Jun 10, 2013, 1:37 AM
YOu need to run CREATE TYPE username AS TABLE ( user_name VARCHAR(30) ) not ..create a table valued type CREATE TYPE username AS TABLE ( user_name VARCHAR(30) )
Puneet AMaRPosted Jun 10, 2013, 12:52 AM
i have got some errors while creating the database ...the error i got is in the line ....."create a table valued type".