Update #temp
Set #temp. Recycle=case when uniona.num>0 then 1 else 0 end
From (select Gradeid,sum (num) as num from Areaallot
where CHARINDEX (@Area, Areaallot.area) =1 and LEN (@Area) =len (area)-2
Group by Gradeid) Uniona INNER JOIN #temp
On uniona.gradeid= #temp. Gradeid
1, for this charindex today tangled a very long time to figure out how to make clear is how a meaning. In order to forget later, so probably make a note.
CHARINDEX (@Area, Areaallot.area) =1 also is the starting position of @area in Areaallot.area, equals 1 means the starting position is first, assuming equals 2 means the starting position is the second position, and so on, but assuming equals 0 means @ Area is not included in the Areaallot.area. The following: Select CHARINDEX (' 43 ', ' 414305 ')
Select CHARINDEX (' 43 ', ' 4305 ') 2, I used to think that group by and order by is a mean, sort. It was only today that group by was used for classification.
Charindex and temporal tables in SQL