夾在中間的重點
有時很幸運,字串的重點剛好在開頭或結尾。不過多半情況下,你會想要從中間某處取出字元。來看看如何使用 RIGHT、LEN、CHARINDEX 和 SUBSTRING 擷取文字字串的中間部分。description 欄位的每一列可能包含多個停電原因。當 description 欄位中出現 Weather 時,我們想要擷取其後的其他停電原因。
本練習屬於課程
SQL Server 入門
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Complete the query to find `Weather` within the description column
SELECT
description,
___('___', description)
FROM
grid
WHERE description LIKE '%Weather%';