Below is my syntax for creating the temp table in MS SQL (and that behaves as expected)
Select stu.STUDENT_GU, stu.sis_number, (Select floor(15 * RAND(convert(varbinary, newid())))+1) as RandomAdj, (Select floor(102 * RAND(convert(varbinary, newid())))+1) as RandomNoun into #Temp1 From rev.EPC_STU stu Join rev.EPC_STU_SCH_YR ssy on stu.STUDENT_GU = ssy.STUDENT_GU and ssy.YEAR_GU = (Select * from rev.SIF_22_Common_CurrentYearGU) Where stu.USER_CODE_6 is null and ssy.STATUS is null and ssy.grade < '160'
Here is my update query and the above temp table has around 1200 records but when I update, it only updates around 300. I cant figure out why it only seems to update some records and not all the records in the temp table. I believe my joins are correct but I am obviously missing something.
Update stu Set USER_CODE_6 = adj.adjective + n.noun From #Temp1 t --Temp1 table Join dbo.pwAdjectives adj on RandomAdj = adj.ID --Adjective Table Join dbo.pwNouns n on RandomNoun = n.ID --Noun Table Join rev.EPC_STU stu on t.STUDENT_GU = stu.STUDENT_GU --Student Table Join rev.EPC_STU_SCH_YR ssy on stu.STUDENT_GU = ssy.STUDENT_GU and ssy.YEAR_GU = (Select * from rev.SIF_22_Common_CurrentYearGU) --Stu School Year table where ssy.GRADE < '160'
Joe Owczarski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.