Soluga
asked on
sql update one table from another
Hi,
I have this statement below.
My assessments table contains 2 published assessments, I want to update the published questions table with the published assessment id, but I keep getting query contained more than one result.
I just want to update individual records from another table.
Maybe I should use a cursor!
Would be grateful for any help.
I have this statement below.
My assessments table contains 2 published assessments, I want to update the published questions table with the published assessment id, but I keep getting query contained more than one result.
I just want to update individual records from another table.
Maybe I should use a cursor!
Would be grateful for any help.
UPDATE tbl_M05_PublishedAssessmentQuestions
SET PublishedAssessmentID =
(SELECT PA.PublishedAssessmentID
FROM tbl_M05_PublishedAssessments PA
WHERE PA.AssessmentID in (Select AssessmentId from tbl_M05_Assessments PAQ)
and PA.PublishedCourseId = @PublishedOnlineCourseReturnID)
UPDATE tbl_M05_PublishedAssessmen tQuestions
SET PublishedAssessmentID =
(SELECT top 1 PA.PublishedAssessmentID
FROM tbl_M05_PublishedAssessmen ts PA
WHERE PA.AssessmentID in (Select AssessmentId from tbl_M05_Assessments PAQ)
and PA.PublishedCourseId = @PublishedOnlineCourseRetu rnID
SET PublishedAssessmentID =
(SELECT top 1 PA.PublishedAssessmentID
FROM tbl_M05_PublishedAssessmen
WHERE PA.AssessmentID in (Select AssessmentId from tbl_M05_Assessments PAQ)
and PA.PublishedCourseId = @PublishedOnlineCourseRetu
ASKER
Pritima,
That updates all the rows with the same publishedAssessmentId
That updates all the rows with the same publishedAssessmentId
change this
where PA.PublishedCourseId = PQ.PublishedCourseId and
with your relationship between two tables
UPdate PQ
Set PQ.PublishedAssessmentID = PA.PublishedAssessmentID
From tbl_M05_PublishedAssessmen tQuestions PQ ,
tbl_M05_PublishedAssessmen ts PA
where PA.PublishedCourseId = PQ.PublishedCourseId and
PA.AssessmentID in (Select AssessmentId from tbl_M05_Assessments PAQ)
where PA.PublishedCourseId = PQ.PublishedCourseId and
with your relationship between two tables
UPdate PQ
Set PQ.PublishedAssessmentID = PA.PublishedAssessmentID
From tbl_M05_PublishedAssessmen
tbl_M05_PublishedAssessmen
where PA.PublishedCourseId = PQ.PublishedCourseId and
PA.AssessmentID in (Select AssessmentId from tbl_M05_Assessments PAQ)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thats what I went with and it worked.
Thanks
Thanks
https://www.experts-exchange.com/A_1517.html