select * from dbo.split(RTRIM(@importRow), '¬')
gives error:
Msg 102, Level 15, State 1, Procedure proc_name, Line 40
Incorrect syntax near ‘(‘.
What is the correct syntax for this line? It’s been a while since I have done SQL properly and can’t for the life of me get this part of the script to execute!
Using SQL Server 2005
I apologise for the Title. Not quite sure what to put other than that or “Syntax error”!
Edit: The code for the SPLIT:
CREATE FUNCTION [dbo].[Split]
(
@String VARCHAR(4000),
@Delimiter VARCHAR(5)
)
RETURNS @SplittedValues TABLE
(
OccurenceId SMALLINT IDENTITY(1,1),
SplitValue VARCHAR(4000)
)
AS
BEGIN
DECLARE @SplitLength INT
WHILE LEN(@String) > 0
BEGIN
SELECT @SplitLength = (CASE CHARINDEX(@Delimiter,@String) WHEN 0 THEN
LEN(@String) ELSE CHARINDEX(@Delimiter,@String) -1 END)
INSERT INTO @SplittedValues
SELECT SUBSTRING(@String,1,@SplitLength)
SELECT @String = (CASE (LEN(@String) - @SplitLength) WHEN 0 THEN ''
ELSE RIGHT(@String, LEN(@String) - @SplitLength - 1) END)
END
RETURN
END
GO
And the code for starting the procedure
CREATE PROCEDURE dbo.[procedure]
-- Add the parameters for the stored procedure here
@RETURN_VALUE int,
@importRow VarChar(8000)
......
Move the RTRIM into the UDF itself (based on comments)
This is good practice anyway so each use of the
splitUDF doeen’t need RTRIM