create function GetSurveyList(@name nvarchar(2000))
returns nvarchar(800)
as
begin
declare @tempFKey varchar(200)
declare @tempFValue varchar(200)
declare @tempresult varchar(max)
set @tempresult=''
--AS
DECLARE rs CURSOR LOCAL SCROLL FOR
select top(5) FKey,FValue from PromotionSurveyRecord where FPromotionClaimID=@name
order by Fsort,FQuestionID
OPEN rs
FETCH NEXT FROM rs INTO @tempFKey,@tempFValue
WHILE @@FETCH_STATUS = 0
BEGIN
set @tempresult=@tempresult+@tempFKey+' : '+@tempFValue+' '
FETCH NEXT FROM rs INTO @tempFKey,@tempFValue
END
CLOSE rs
deallocate rs
return @tempresult
end
select dbo.GetSurveyList('EC89D126-0C6B-40C6-96E3-73E74E890CEC') as Temp
select * ,dbo.GetSurveyList(FID),from ViewProgramPromotionClaim
sql自定义函数与游标的结合使用
最新推荐文章于 2023-04-07 11:06:40 发布