STRING_SPLIT: Splitting strings into multiple rows using SQL Server using a delimiter or separator

preview_player
Показать описание
In this video, we will be looking at how to use a delimiter or separator to split a string into multiple rows.
My SQL Server Udemy courses are:
----
In this video, I'm showing you how to split a string into multiple rows using SQL Server using a delimiter or separator.

If you're working with a large string that you want to split into multiple rows, then this technique is perfect for you. By splitting the string into multiple rows, you can more easily handle and analyze the data. Plus, this technique is easy to apply using SQL Server, so you'll be able to get started quickly!

If you have a string such as "Jacksonville,Tampa,Orlando,Miami,Tallahassee", how can you separate it into 5 different rows? In this video, we'll have a look at STRING_SPLIT (which you can use from SQL server 2016 onwards).
It uses 2 arguments - the string to be split, and the one character delimiter or separator.
It returns one column which is called "value". If you are using an Azure database, then you can use a third argument to return a second column called "ordinal", which numbers the output.
Here is an example of how you would use it:
DECLARE @strText AS VARCHAR(300) = 'Jacksonville,Tampa,Orlando,Miami,Tallahassee'
SELECT @strText as MyText

You can also use CROSS APPLY to use it in conjunction with another table or view:
SELECT ProductDescriptionID, trim(Value) as Sentence
FROM [Production].[ProductDescription]
CROSS APPLY
STRING_SPLIT(Description, '.')

In Azure SQL, you can add the third argument, such as:
STRING_SPLIT(Description, '.', 1)
Рекомендации по теме
Комментарии
Автор

love this video - easy & straight forward
clear english is an asset here :D

shadowitself
Автор

Thank you very much! Very informative and saved my time.

ozlemmenderes
Автор

Can we have a video on how to do row versioning?

joshiqwe
Автор

How did the cross-apply work here as we have not provided any where condition. Also, I believe if we don’t apply the where condition then it connect every row of first table with another, something like cross join. Can you pls help me to understand? Thanks

vivekparashar
Автор

I don't have the split function, I am using the 2012 version, any suggestions on how to split 4 strings in one column into 4.

solomong.gebrhana
Автор

Help but if we want to split based on length, 60 characters in each row

prithvipampana
Автор

I am using 2016 version, SPLIT_STRING is not available. Can we do without SPLIT_STRING?

udaykiranr
Автор

What if B.C.C. is present ? And we don't want to split B.C.C.
Please Provide solution

nikhilkrishn
Автор

Hi Suppose i am having a word like "Server" As input.
My output should be in differrnr lines.
Output :
S
E
R
V
E
R
This is simple in python. But not sure how to do it in sql. Repeated sql question in interview
Thanks in advance

dineshkumarp
Автор

I have a question: How to Separate a word like this and the result is "this How to separate this word in one colum"

datsmeWT