Ho la seguente tabella:
==========================================================
| Name_Level_Class_Section | Phone Num |
==========================================================
| Jacky_1_B2_23 | 1122554455 |
| Johnhy_1_B2_24 | 1122554455 |
| Peter_2_A5_3 | 1122554455 |
==========================================================
Sto pensando di semplificare la mia istruzione SQL come segue:
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
In modo che quando eseguo l'SQL, mi darà il seguente risultato:
==========================================================
| 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 |
==========================================================
C'è un modo per semplificare il mio SQL?