During the Sui Dynasty, the main purpose of digging canals and digging Yongji Canal leading to Zhuozhou was clear. At that time, it was to solve the problem of grain and grass transportation for the expedition to Koguryo (North Korea) and provide necessary logistical support for the war in the north. Tongji Canal leading to Yangzhou has nothing to do with the war, and its main purpose is to facilitate the transportation of grain from Jianghuai area to Luoyang and then to Chang 'an.
In the Tang Dynasty, China's economic center of gravity moved to the southeast more obviously. By the end of the Tang Dynasty, the Guanzhong area relied almost entirely on the supply of grain and grass in the Jianghuai area. So in the Sui Dynasty, Guanzhong was short of resources. According to historical records, whenever there is a famine in Guanzhong, the emperor will lead officials of civil and military forces and Guanzhong people to eat in Luoyang from Chang 'an, that is, to eat in Luoyang. So at that time, Guanzhong could not afford the huge imperial court, and needed to mobilize food from the southeast, especially the Jianghuai area, and supply it to the central government. In ancient times, which was dominated by water transportation, it was imperative to dig a grand canal leading to the capital.
The excavation of the Grand Canal in Sui and Tang Dynasties also kept Chang 'an as the capital, but once the traffic was cut off, it would cause great panic. At the end of the Tang Dynasty, Zhu Wen forced the Tang Dynasty to move its capital to Luoyang, and in the Song Dynasty, in order to further shorten the transportation line, Kaifeng was directly used as the capital. So in ancient China, unless the court wanted to be partial to Jiang Zuo. Otherwise, a core problem is how to transport food and materials from the rich southeast to the capital.
It is a strategic necessity for the Yuan Dynasty to establish its capital in today's Beijing. At that time, the rear area of the Yuan Dynasty was on the Mongolian Plateau. In order to maintain a stable situation, the forces of the Yuan Dynasty should not be too far away from the home front. Therefore, the rulers of the Yuan Dynasty had to solve the problem of transporting grain from south to north. So there is today's Beijing-Hangzhou Grand Canal.