用户定义函数的“表达式"参数数据类型

2021-09-10 00:00:00 tsql sql-server

我正在尝试创建一个将 表达式作为参数的函数

I am trying to create a function that takes as a parameter an expression like what is used with BINARY_CHECKSUM. Specifically, I want my parameter to be a list of 1 to N column names. When I look at the definition of BINARY_CHECKSUM (or MAX or CHECKSUM for that matter) in Object Explorer in SQL Server Management Studio the parameter is defined as 'Expression (any type)'- can a user-defined function emulate this? I know that I could use a parameter a delimited list of comma names, but I'm curious about 'Expression (any type)'.

推荐答案

如果您想在 SQL 中编写自己的聚合函数(例如 BINARY_CHECKSUMCOUNT 等)Server 2005 或更高版本,您将不得不使用 CLR.请参阅 MSDN 上的以下内容:

If you want to write your own aggregate functions (like BINARY_CHECKSUM, COUNT, etc) in SQL Server 2005 or later, you'll have to use the CLR. See the following on MSDN:

如何:创建和运行 CLRSQL Server 聚合
创建聚合

相关文章