Tengo la siguiente tabla:
==========================================================
| Name_Level_Class_Section | Phone Num |
==========================================================
| Jacky_1_B2_23 | 1122554455 |
| Johnhy_1_B2_24 | 1122554455 |
| Peter_2_A5_3 | 1122554455 |
==========================================================
Estoy pensando en simplificar mi declaración SQL de la siguiente manera:
select
*,
substring(Name_Level_Class_Section,
CHARINDEX('_',Name_Level_Class_Section,
(CHARINDEX('_', Name_Level_Class_Section) + 1)) + 1,
CHARINDEX('_',Name_Level_Class_Section,
(CHARINDEX('_',Name_Level_Class_Section,
(CHARINDEX('_',Name_Level_Class_Section)+1))+1))-
CHARINDEX('_',Name_Level_Class_Section,
(CHARINDEX('_',Name_Level_Class_Section)+1))) as CLA
from
Bookings
order by
CLA asc, Name_Level_Class_Section asc
De modo que cuando realizo el SQL, me dará el siguiente resultado:
==========================================================
| Name_Level_Class_Section | Phone Num | CLA |
==========================================================
| Jacky_1_B2_23 | 1122554455 | B2 |
| Johnhy_1_B2_24 | 1122554455 | B2 |
| Peter_2_A5_3 | 1122554455 | A5 |
==========================================================
¿Hay alguna forma de simplificar mi SQL?