Skip to content

Instantly share code, notes, and snippets.

@johnvilsack
Created October 23, 2012 20:52
Show Gist options
  • Save johnvilsack/3941473 to your computer and use it in GitHub Desktop.
Save johnvilsack/3941473 to your computer and use it in GitHub Desktop.
Kris' Super Special Function for Splitting
SELECT TOP 1000 * FROM dbo.doSplit(store_data.feature_list,'<LI>Effective');
SELECT TOP 1000 * FROM dbo.doSplit('<B>Key Features of The Forum Roost 164cm Snowboard:</b><br>
<LI>SuperGnar LE Core</LI>
<LI>Light Triax Laminates</LI>
<LI>Formula Base</LI>
<LI>Directional Tapered Board Shape</LI>
<LI>Directional Core Profile</LI>
<LI>Flex - 6</LI>
<LI>Effective Edge (cm) - 128.00</LI>
<LI>Nose/Tail (cm) - 30.91/29.85</LI>
<LI>Waist (cm) - 25.40</LI>
<LI>Sidecut (m) - 8.00</LI>','<LI>Effective');
//Create Function to split at value
CREATE FUNCTION dbo.doSplit
(
@RowData nvarchar(2000),
@SplitOn nvarchar(50)
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Data nvarchar(1000)
)
AS
BEGIN
Declare @Cnt int
Set @Cnt = 1
While (Charindex(@SplitOn,@RowData)>0)
Begin
Insert Into @RtnValue (data)
Select
Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
Set @Cnt = @Cnt + 1
End
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(@RowData))
Return
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment