create table split string function in sql server
SELECT
first_name,
last_name,
value phone
FROM
sales.contacts
CROSS APPLY STRING_SPLIT(phones, ',');
create table split string function in sql server
SELECT
first_name,
last_name,
value phone
FROM
sales.contacts
CROSS APPLY STRING_SPLIT(phones, ',');
sql Split string function
CREATE FUNCTION [dbo].[Func_SplitString]
( @Values VARCHAR(MAX)
, @splitStr VARCHAR(50)
)
RETURNS @Result_Table TABLE
(
[value] nvarchar(MAX) NULL
)
BEGIN
DECLARE @TempStr nvarchar(MAX)
WHILE (CHARINDEX(@splitStr,@Values)>0)
BEGIN
SET @TempStr=SUBSTRING(@Values,1,CHARINDEX(@splitStr,@Values)-1)
INSERT INTO @Result_Table (value) VALUES (ltrim(rtrim(isnull(@TempStr, ''))))
SET @Values = REPLACE(@Values,@TempStr+@splitStr,'')
END/*End While*/
IF(LEN(RTRIM(LTRIM(@Values)))>0 AND CHARINDEX(@splitStr,RTRIM(LTRIM(@Values)))=0)
BEGIN
SET @TempStr=@Values
INSERT INTO @Result_Table (value) VALUES (ltrim(rtrim(isnull(@TempStr, ''))))
End /*End IF*/
RETURN
END
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us