What is the object & ldquo; & quot; equivalent in SQL Server?

advertisements

I would like to create a user defined function that can receive any type. My question is what is the type that is equivalent to "object" in language like C#/Java that I need to put on my function.

For example, if I design/call my function like that :

CREATE FUNCTION dbo.MyFunction(@value int)
...
SELECT dbo.MyFunction('a');

I will receive the following exception :

Conversion failed when converting the varchar value 'a' to data type int.

Is varchar(max) the type I'm looking for? Why?


sql_variant is the closest you'll get, but there are plenty of types (mostly the newer ones) that it won't accept:

The following table lists the types of values that cannot be stored by using sql_variant:

varchar(max)

varbinary(max)

nvarchar(max)

xml

text

ntext

image

rowversion (timestamp)

sql_variant

geography

hierarchyid

geometry

User-defined types

datetimeoffset