Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can T-SQL function return user-defined table type? [duplicate]

Tags:

I have my own type:

CREATE TYPE MyType AS TABLE
(
    foo INT
)

and a function receiving it as a parameter:

CREATE FUNCTION Test
(
    @in MyType READONLY
)
RETURNS @return MyType
AS
...

can it return MyType or only TABLE repeating MyType's structure:

CREATE FUNCTION Test
(
    @in MyType READONLY
)
RETURNS @return TABLE (foo INT)
AS
...

?

like image 632
abatishchev Avatar asked Mar 23 '10 15:03

abatishchev


People also ask

Which of the following data types can be returned from a user defined T SQL function in SQL Server?

For a multistatement scalar function, the function body can contain a series of Transact-SQL statements that return the single value. The return type can be any data type except text, ntext, image, cursor, and timestamp.

How can access user defined table type in SQL Server?

Once you connect to a database in SSMS, you can view these data types by navigating to Programmability-> Types->System Data Types.

Can we alter user defined table type in SQL Server?

Unlike tables, a table type cannot be altered by a simple command. I need to do the following: Rename existing table type. Create the new table type.

How do you change a user defined table?

The user-defined table type definition cannot be modified after it is created. You will need to drop any procedures or functions which depend on the type; drop the type; create the type with the new definition; and finally re-create the dependant procedures / functions.


1 Answers

As far as I understand Microsoft's MSDN article here, those user-defined table types are only available as read-only parameters to stored procedures or stored functions.

It doesn't mention anything that they could be used to be returned from a user-defined function, unfortunately - so I guess you're right - it's not possible (at least not now).

like image 193
marc_s Avatar answered Oct 05 '22 17:10

marc_s