Monday, 11 August 2014
Friday, 8 August 2014
update multiple rows single query sql server
declare @SymptomID int=46
update MD_RS_SymptomsReviewQuestions
set Sequence = bb.Number
from MD_RS_SymptomsReviewQuestions
join
(
select a.* --ROW_NUMBER() over (ORDER BY id) AS Number
from MD_RS_SymptomsReviewQuestions a
where a.SymptomID = @SymptomID
and a.IsDeleted = 0
and a.Sequence <= 0
)aa
on aa.ID = MD_RS_SymptomsReviewQuestions.ID
join
(
select b.ID, ROW_NUMBER() over (ORDER BY id) AS Number
from MD_RS_SymptomsReviewQuestions b
where b.SymptomID = @SymptomID
and b.IsDeleted = 0
and b.Sequence <= 0
)bb
on bb.ID = aa.ID
update MD_RS_SymptomsReviewQuestions
set Sequence = bb.Number
from MD_RS_SymptomsReviewQuestions
join
(
select a.* --ROW_NUMBER() over (ORDER BY id) AS Number
from MD_RS_SymptomsReviewQuestions a
where a.SymptomID = @SymptomID
and a.IsDeleted = 0
and a.Sequence <= 0
)aa
on aa.ID = MD_RS_SymptomsReviewQuestions.ID
join
(
select b.ID, ROW_NUMBER() over (ORDER BY id) AS Number
from MD_RS_SymptomsReviewQuestions b
where b.SymptomID = @SymptomID
and b.IsDeleted = 0
and b.Sequence <= 0
)bb
on bb.ID = aa.ID
Subscribe to:
Comments (Atom)