我正在尝试使用 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