t-sql udf,获取参数的数据类型

时间:2022-11-25 16:30:44

is it possible to get a numeric parameter to my udf and do stuff according to its type, like:

是否有可能为我的udf获取一个数字参数并根据其类型执行操作,例如:

if type of @p1 is decimal(10,3) ... else if type of @p1 is decimal(15,3) ... else if type of @p1 is integer ...

如果@ p1的类型是十进制(10,3)...如果@ p1的类型是十进制(15,3),则其他...如果@ p1的类型是整数...

2 个解决方案

#1


Try out the sql_variant_property function...

试试sql_variant_property函数......

Some examples...

Declare @Param Int
Set @Param = 30
Select sql_variant_property(@Param, 'BaseType')
Select sql_variant_property(@Param, 'Precision')
Select sql_variant_property(@Param, 'Scale')

Declare @ParamTwo float
Set @ParamTwo = 30.53
Select sql_variant_property(@ParamTwo, 'BaseType')
Select sql_variant_property(@ParamTwo, 'Precision')
Select sql_variant_property(@ParamTwo, 'Scale')

Hope it helps :)

希望能帮助到你 :)

#2


You should know what type is declared as in the function parameters.

您应该知道在函数参数中声明了什么类型。

The udf parameters and return type are explicitly declared as "int" or "decimal(p,s)" etc... no need to work it out...

udf参数和返回类型显式声明为“int”或“decimal(p,s)”等...不需要解决它...

#1


Try out the sql_variant_property function...

试试sql_variant_property函数......

Some examples...

Declare @Param Int
Set @Param = 30
Select sql_variant_property(@Param, 'BaseType')
Select sql_variant_property(@Param, 'Precision')
Select sql_variant_property(@Param, 'Scale')

Declare @ParamTwo float
Set @ParamTwo = 30.53
Select sql_variant_property(@ParamTwo, 'BaseType')
Select sql_variant_property(@ParamTwo, 'Precision')
Select sql_variant_property(@ParamTwo, 'Scale')

Hope it helps :)

希望能帮助到你 :)

#2


You should know what type is declared as in the function parameters.

您应该知道在函数参数中声明了什么类型。

The udf parameters and return type are explicitly declared as "int" or "decimal(p,s)" etc... no need to work it out...

udf参数和返回类型显式声明为“int”或“decimal(p,s)”等...不需要解决它...