我必须删除此选择的结果。 我试图创建一个新表并在其中插入select的结果,然后删除。 谁能帮帮我?
select *
from SurveySession ss (nolock)
left join
SurveySessionPages sp
on ss.Id = sp.SurveySessionID
left join
SurveySessionAnswers sa
on ss.Id = sa.SurveySessionID
left join
SurveySessionAnswerChoices sac
on sa.Id = sac.SurveySessionAnswerId
left join
SurveySessionXmlData sxd
on ss.Token = sxd.Token
where ss.StartedOn <= dateadd(day,datediff(day,0,getdate())-365,0)
and (ss.UpdatedOn is null or ss.UpdatedOn <= dateadd(day,datediff(day,0,getdate())-365,0)))
答案 0 :(得分:0)
您可以将查询用作子查询并删除其结果。
DELETE FROM SurveySession WHERE Id=(select *
from SurveySession ss (nolock)
left join
SurveySessionPages sp
on ss.Id = sp.SurveySessionID
left join
SurveySessionAnswers sa
on ss.Id = sa.SurveySessionID
left join
SurveySessionAnswerChoices sac
on sa.Id = sac.SurveySessionAnswerId
left join
SurveySessionXmlData sxd
on ss.Token = sxd.Token
where ss.StartedOn <= dateadd(day,datediff(day,0,getdate())-365,0)
and (ss.UpdatedOn is null or ss.UpdatedOn <= dateadd(day,datediff(day,0,getdate())-365,0))))
答案 1 :(得分:0)
您可以添加delete
而不是select
,并按照这样做。
delete SurveySession
from SurveySession ss
left join
SurveySessionPages sp
on ss.Id = sp.SurveySessionID
left join
SurveySessionAnswers sa
on ss.Id = sa.SurveySessionID
left join
SurveySessionAnswerChoices sac
on sa.Id = sac.SurveySessionAnswerId
left join
SurveySessionXmlData sxd
on ss.Token = sxd.Token
where ss.StartedOn <= dateadd(day,datediff(day,0,getdate())-365,0)
and (ss.UpdatedOn is null or ss.UpdatedOn <= dateadd(day,datediff(day,0,getdate())-365,0)))
答案 2 :(得分:0)
你需要回答NoDisplayName的问题才能获得明确的答案,但是: