dir.by  
  Поиск  
Компьютер, программы
Microsoft SQL Server (database, server) and SQL Management Studio (a program for working with SQL server). Only works on Windows
 How to use the SQL query to split a string into words using the delimiter in SQL Server ? Creating a Stored Function in SQL Server Management Studio  
Step 1. Open SQL Server Management Studio
Note! You must have Microsoft SQL Server installed. If you don't have it, then need to download and install Microsoft SQL Server ...

Note! You must have SQL Server Management Studio installed. If you don't have it, then need to download and install SQL Server Management Studio ...

To open SQL Server Management Studio, we click on the icon on the desktop:
Old version SQL Server Management Studio (this is version 18)
New version SQL Server Management Studio (this is version 22)
 
A window will appear and press the "Connect" button:
 
Old version SQL Server Management Studio (this is version 18)
New version SQL Server Management Studio (this is version 22)
 
After 20 seconds, we will see that SQL Server Management Studio is loaded:
Old version SQL Server Management Studio (this is version 18)
New version SQL Server Management Studio (this is version 22)
Step 2. Create a stored function in SQL Server Management Studio
If you do not have created a database MyDatabase1 , then Creating a database MyDatabase1...

Click on DatabasesMyDatabase1Programmability → Functions → Table-valued Functions
Right-click on Table-valued Functions and select New Inline Table-valued Function ...
Step 3. Let's write code for the stored function
CREATE FUNCTION [dbo].[fn_SplitString]
(
     @SourceString VARCHAR(MAX),
     @Seperator VARCHAR(25)=','
)

RETURNS @ResultTable

TABLE(
     [Position] INT IDENTITY(1,1),
     [Value] VARCHAR(MAX)
)

AS
BEGIN

     DECLARE @w_xml xml;

     SET @w_xml = N'<root><i>' + replace(@SourceString, @Seperator,'</i><i>') + '</i></root>';

     INSERT INTO @ResultTable
          ([Value])
     SELECT
          [i].value('.', 'VARCHAR(MAX)') AS Value
     FROM
          @w_xml.nodes('//root/i') AS [Items]([i]);

     RETURN;
END;
GO
 
Let's click on execute and see the successful execution:
 
Let's click on Refresh and see our new function:
Step 4. Let's run our stored function
Create a new query:
 
Let's write the code:
SELECT * from dbo.fn_SplitString('Hello, thank you, bye!', ',')
 
Click on Execute and see the result:
 
← Previous topic
Create a stored procedure in SQL Server Management Studio
 
Next topic →
Looking at the values in the table in SQL Server Management Studio
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

  Объявления  
  Объявления  
 
Microsoft SQL Server
What is Microsoft SQL Server?
Download and install Microsoft SQL Server (2025, 2019, 2017, 2012, another version)
Non-Clustered indexes in SQL Server
Clustered indexes in SQL Server
Microsoft SQL Server Management Studio (SQL Server Database Program)
What is SQL Server Management Studio? How to download and install SQL Server Management Studio 2017...
Open (run) SQL Server Management Studio
Creating a database
Creating a Database in SQL Server Management Studio
Creating a table
What is a table in the Database?
Create a table in SQL Server Management Studio
Create a stored procedure
Create a stored procedure in SQL Server Management Studio
To create a stored function
Creating a Stored Function in SQL Server Management Studio How to use the SQL query to split a string into words using the delimiter in SQL Server ?
Look at the values in the table
Looking at the values in the table in SQL Server Management Studio
Editing the values in the table
Editing the values in the table in SQL Server Management Studio
Create user
Create user "evgen" for Sql Server in Microsoft SQL Server Management Studio

  Ваши вопросы присылайте по почте: info@dir.by