我正在尝试使用CURSOR表在函数中传递两个值。它是否正确?我从早些时候修改了这篇文章。当我执行此功能时,它会成功执行。只是不确定如何在SQL中进行测试。
USE [PMCLW1]
GO
/****** Object: UserDefinedFunction [dbo].[func_PNMS_CA] Script Date: 08/13/2013 14:41:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER function [dbo].[func_PNMS_CA](@SCRDET_Seqid int, @JobSeqid int)
returns varchar(5000)
as
begin
declare @retVal varchar(5000),
@temp varchar(1000)
declare CACur CURSOR FOR
SELECT top 1 isnull (SPCOPS_Answer, '') FROM SPCOPS WHERE SCRDET_Seqid = @SCRDET_Seqid
declare CACur CURSOR FOR
SELECT b.JBSTAT_Description
FROM JBWORK a
inner join JBSTAT b on a.JBSTAT_SEQID = b.JBSTAT_SEQID
WHERE a.PRJOBS_SEQID = @JobSeqid
and a.dptmnt_seqid=7
OPEN CACur
FETCH NEXT FROM CACur
INTO @temp
set @retVal = ''
WHILE @@FETCH_STATUS = 0
BEGIN
IF len(@retVal) = 0 set @retVal = @temp
ELSE set @retVal = @retVal + ', ' + @temp
FETCH NEXT FROM CACur
INTO @temp
END
close CACur
deallocate CACur
return @retVal
end