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. It takes a long time to figure out the meaning of this CHARINDEX. To forget it later, take a note,
CHARINDEX (@ Area, AreaAllot. area) = 1 and @ Area in AreaAllot. the starting position in the Area. equal to 1 indicates that the starting position is the first place. If it is equal to 2, it indicates that the starting position is the second place, if the value is 0, @ Area is not included in AreaAllot. area. Column: select CHARINDEX ('43 ', '123 ')
Select CHARINDEX ('43 ', '000000') 2. I used to think that group by and order by mean sorting. Today I know that group by is used for classification.