Insert Student
INSERT INTO SS_Replies
SELECT distinct NEWID(),SS_Replies.Text,SS_Replies.Rating,GETDATE(),GETDATE(),Null,'043D7B57-03F7-4A35-82E9-8E7AF358B70C',null,SS_Replies.[Option],SS_Replies.Question,SS_Respondents.Id,SS_Sessions.Id,'043D7B57-03F7-4A35-82E9-8E7AF358B70C',SS_Replies.ZoneItemId,Null,Null,Null,Null,Null
FROM SS_Respondents
INNER JOIN SS_Sessions
ON SS_Sessions.Id=SS_Respondents.SessionId
INNER JOIN [SS_Definitons]
ON SS_Sessions.Definition=[SS_Definitons].Id
INNER JOIN [SS_Terms]
ON [SS_Definitons].Term=[SS_Terms].Id
INNER JOIN SS_Replies
ON SS_Replies.Respondent='0f398e07-f406-e811-80d6-00155d3c406b'
WHERE SS_Terms.Ancestor='E834EB6F-7A3B-457A-886D-E7C14EC2C113' AND SS_Sessions.AdHoc=0 And SS_Sessions.TargetKind=1 AND SS_Respondents.State=0
AND SS_Sessions.Id in(
SELECT TOP 10 SS_Respondents.Sessionid
FROM SS_Respondents WHERE SS_Respondents.State=0 Group By SS_Respondents.Sessionid Having Count(SS_Respondents.Id)=520
ORDER BY SS_Respondents.Sessionid
)
GO
--SELECT distinct Session FROM SS_Replies
--WHERE Session ='48017F59-5902-E811-80D6-00155D3C406B'
--SELECT * FROM SS_Replies WHERE Respondent='0f398e07-f406-e811-80d6-00155d3c406b'
--SELECT Count(Session) FROM SS_Replies
UPDATE SS_Respondents SET SS_Respondents.State=1 WHERE SS_Respondents.SessionId in(
SELECT TOP 10 SS_Respondents.Sessionid
FROM SS_Respondents WHERE SS_Respondents.State=0 Group By SS_Respondents.Sessionid Having Count(SS_Respondents.Id)=520 ORDER BY SS_Respondents.Sessionid)
GO
UPDATE SS_Sessions SET State=5 WHERE Id in(
SELECT TOP 10 SS_Respondents.Sessionid
FROM SS_Respondents WHERE SS_Respondents.State=0 Group By SS_Respondents.Sessionid Having Count(SS_Respondents.Id)=520 ORDER BY SS_Respondents.Sessionid)
GO