我必须创建一个内联函数(不允许存储过程,因为最终用户无法访问它,因为性能问题而不允许多语句功能)。我被一段代码搞砸了。
代码是这样的。
ALTER FUNCTION [CDC].[FN_CBR_COPERNICUS_DBO_AGMASTER_ANY] (
@START_LSN BINARY (10)
,@END_LSN BINARY (10)
,@APPLNID SMALLINT
)
RETURNS TABLE
AS
RETURN (
SELECT (
SELECT STUFF((
SELECT ', ' + CBR.CBRCA_COLUMNNANME
FROM CBRCOLAPPLN CBR
WHERE CBR.CBRCA_APPLICATIONID = 1
AND CBR.CBRCA_TABLENAME = 'COPERNICUS_CORE_PARAMETER'
FOR XML PATH('')
,TYPE
).VALUE('.', 'NVARCHAR(MAX)'), 1, 2, ' ') CHANGED_COLUMNS
)
,__$OPERATION AS CBR_OPERATION
FROM CBR.FN_CBR_GET_NET_CHANGES_ES_CMS_DBO_COPERNICUS_CORE_PARAMETER(0x0009631C000016F90029, 0x0009631D000008720001, 'ALL WITH MASK') AS CBRUPDATEDCOLUMNS
)
子查询select将返回值,如果我单独执行子查询,则返回以下
CMS_ID
,CMS_PARA_NAME
,CMS_PARA_TYPE
,CMS_PARA_MODULE
,CMS_PARA_VALUE
,CMS_COMMENTS
,CMS_ACTIVE_YN
当我将子查询的值放在函数中并将代码放在
时SELECT CMS_ID
,CMS_PARA_NAME
,CMS_PARA_TYPE
,CMS_PARA_MODULE
,CMS_PARA_VALUE
,CMS_COMMENTS
,CMS_ACTIVE_YN
,__$operation AS CBR_OPERATION
FROM CBR.FN_CBR_GET_NET_CHANGES_ES_CMS_DBO_COPERNICUS_CORE_PARAMETER(0x0009631C000016F90029, 0x0009631D000008720001, 'all with mask') AS CBRUPDATEDCOLUMNS
执行它后,我从函数CBR.FN_CBR_GET_NET_CHANGES_ES_CMS_DBO_COPERNICUS_CORE_PARAMETER
然而,如果我执行第一组代码(在函数中编写的代码),放在问题的开头,它只会导致子查询的值*函数中的行数 。它只是给我下面的结果,以及一些__ $ OPERATION值
CMS_ID, CMS_PARA_NAME, CMS_PARA_TYPE, CMS_PARA_MODULE, CMS_PARA_VALUE, CMS_COMMENTS, CMS_ACTIVE_YN
CMS_ID, CMS_PARA_NAME, CMS_PARA_TYPE, CMS_PARA_MODULE, CMS_PARA_VALUE, CMS_COMMENTS, CMS_ACTIVE_YN
CMS_ID, CMS_PARA_NAME, CMS_PARA_TYPE, CMS_PARA_MODULE, CMS_PARA_VALUE, CMS_COMMENTS, CMS_ACTIVE_YN
CMS_ID, CMS_PARA_NAME, CMS_PARA_TYPE, CMS_PARA_MODULE, CMS_PARA_VALUE, CMS_COMMENTS, CMS_ACTIVE_YN
你能帮助我在哪里出错吗?