sql - update field value with multiple rows -
i have stored proc have temp table , need update value of "day_name" column. loop throug temp table , update value
this example of data(there multiple student names):
student studentid courseid course_name period day_name bray, clifford 14088 10064 physical education 9gym 1 bray, clifford 14088 10064 physical education 9gym 1 b bray, clifford 14088 10064 physical education 9gym 1 c bray, clifford 14088 10064 physical education 9gym 1 d bray, clifford 14088 10064 physical education 9gym 2 bray, clifford 14088 10064 physical education 9gym 2 b bray, clifford 14088 10064 physical education 9gym 2 c bray, clifford 14088 10064 physical education 9gym 2 d bray, clifford 14088 10065 physical education 11gym 3 b bray, clifford 14088 10065 physical education 11gym 3 d bray, clifford 14088 10065 physical education 11gym 5 bray, clifford 14088 10065 physical education 11gym 5 c bray, clifford 14088 10065 physical education 11gym 6 bray, clifford 14088 10065 physical education 11gym 6 b bray, clifford 14088 10065 physical education 11gym 6 c bray, clifford 14088 10065 physical education 11gym 6 d bray, clifford 14088 10059 health 9p373 7 bray, clifford 14088 10059 health 9p373 7 b bray, clifford 14088 10059 health 9p373 7 c
i data this:
student studentid courseid course_name period day_name bray, clifford 14088 10064 physical education 9gym 1 abcd bray, clifford 14088 10064 physical education 9gym 2 abcd bray, clifford 14088 10065 physical education 11gym 3 bd bray, clifford 14088 10065 physical education 11gym 5 ac bray, clifford 14088 10065 physical education 11gym 6 abcd bray, clifford 14088 10059 health 9p373 7 abc
thanks in advance:) please please help....
given have finite list of day names, easiest way explicit aggregation:
select student, studentid, courseid, course_name, period, (max(case when day_name = 'a' day_name else '' end) + max(case when day_name = 'b' day_name else '' end) + max(case when day_name = 'c' day_name else '' end) + max(case when day_name = 'd' day_name else '' end) ) days table t group student, studentid, courseid, course_name, period;
if want table this, suggest create new table. modifying original 1 doesn't make sense -- have delete rows modifying or inserting values.
Comments
Post a Comment