-- ===================================================== ======
-- Author: <author, Name>
-- Create Date: <create date,>
-- Description: The SQL function implements the C # split function.
-- ===================================================== ======
Set ansi_nulls on
Set quoted_identifier on
Go
Alter function [DBO]. [splitstr]
(
@ Sourcesql varchar (8000), ----- source string ----
@ Strseprate varchar (10) ---- delimiter ---
)
Returns float
As
Begin
Declare @ ch as int
Declare @ temp as float
Set @ temp = 0
Set @ sourcesql = rtrim (ltrim (@ sourcesql ))
Set @ CH = charindex (@ strseprate, @ sourcesql)
While (@ ch> 1)
Begin
Set @ temp = @ temp + convert (float, (left (@ sourcesql, @ CH-1 )))
Set @ sourcesql = substring (@ sourcesql, @ CH + 1, (LEN (@ sourcesql)-@ ch ))
Set @ CH = charindex (@ strseprate, @ sourcesql)
End
Return @ temp
End