可以在存储过程中使用类似数组的东西去存储一个数据么
select a.EstimateContent,a.FKAbilityProjectID
from estimate_project a ,semester_course_ships b
where a.FKCourseID = '068bbb85-c8f9-4691-945d-09462170dd0c' and a.FKCourseID= b.PKSemesterCourseID and b.FKCourseID = '4ad0e6dc-cc57-4131-9415-50decd8b51eb'
and a.FKAbilityProjectID='010101'
----这是我要查询的代码,a.FKAbilityProjectID的值在下面那段SQL中取出来
select PKAbility_ProjectID from ability_project where ParentID in(select PKAbility_ProjectID from ability_project where Levels=2
and ParentID in (01)) and Levels=3 --值为(010101,010102,010201,010202)
想做个循环取值,使 a.FKAbilityProjectID分别在010101,010102,010201,010202中取值。
请教各位大神指导下 我在存储过程中该怎么写?才能做到循环四次取值 存储
[解决办法]
--仅供参考:
DECLARE @json NVARCHAR(MAX)
SET @json = '[' + STUFF(
(SELECT ',{"PKAbility_ProjectID":"' + PKAbility_ProjectID + '"}'
FROM ability_project
WHERE ParentID IN ( SELECT PKAbility_ProjectID
FROM ability_project
WHERE Levels = 2
AND ParentID IN ( 01 ) )
AND Levels = 3 --值为(010101,010102,010201,010202)
FOR XML PATH('')),1,1,''
) + ']'
SELECT @json
/*
[{"PKAbility_ProjectID":"010101"},{"PKAbility_ProjectID":"010102"}]
*/