Reputation: 4753
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?
Upvotes: 1
Views: 868
Reputation: 19184
If you post a custom object from Javascript, it is serialised as JSON. That's how javascript represents a custom object. Maybe you could do the same.
Upvotes: 0
Reputation: 239664
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
Upvotes: 2