Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a table valued parameter to stored procedure have default values

Tags:

sql

sql-server

Suppose that I have a two column User Defined Table type

CREATE TYPE [Schema].[Type] AS TABLE (
    [Name]         NVARCHAR (100) NULL
    [Value]         int NULL
);

Further suppose that I have stored procedure that I pass the table type to

CREATE PROCEDURE [Schema].[sp_SomeProcedure]
@TVP [Type] READONLY
AS
SELECT 
[Name]
,1 + [Value]
FROM
@TVP

Can I default the value of @TVP to be

(SELECT 'John', 1)  
like image 655
cronos2546 Avatar asked Dec 24 '22 13:12

cronos2546


1 Answers

You can use the 'DEFAULT' keyword for the TVP when calling the procedure. That will pass an empty table of the type.

Example - if the TVP is the second parameter passed to a procedure:

    Exec myProcedure (intParam, DEFAULT) 
like image 59
Kimber Avatar answered Dec 27 '22 03:12

Kimber