เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Splitting a string into pieces

Besides concatenating multiple row values, a common task is to split a string into pieces.

Starting with SQL Server 2016, there is a built-in function for achieving this task: STRING_SPLIT(string, separator).

This function splits the string into substrings based on the separator and returns a table, each row containing a part of the original string.

Remember: because the result of the function is a table, it cannot be used as a column in the SELECT clause; you can only use it in the FROM clause, just like a normal table.

In this exercise, you will get familiar with this function.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Functions for Manipulating Data in SQL Server

ดูคอร์ส

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

DECLARE @phrase NVARCHAR(MAX) = 'In the morning I brush my teeth. In the afternoon I take a nap. In the evening I watch TV.'

SELECT value
FROM ___;
แก้ไขและรันโค้ด