0
DECLARE @timeRange as varchar(max)
SET @timeRange= '00:30-01:00**00:20-01:00'

DECLARE @tblTime TABLE(RowNum int identity(1,1),TimeRange ntext)

INSERT INTO @tblTime SELECT rtrim(ltrim(items)) from split(@timeRange,'**')
select *from @tblTime

The above procedure is returning three rows with the middle being null

And

DECLARE @timeRange as varchar(max)
SET @timeRange= '00:30-01:00*00:20-01:00'

DECLARE @tblTime TABLE(RowNum int identity(1,1),TimeRange ntext)

INSERT INTO @tblTime SELECT rtrim(ltrim(items)) from split(@timeRange,'*')
select *from @tblTime

The above code is returning two rows exactly what I wanted.

I'd like to know why the split() function affects my result.

I have concatenated string with ** first then split, the result is different from the string concatenated with *. EDITED: the split function is from SageFrame

mesimplybj
  • 639
  • 1
  • 5
  • 28

1 Answers1

0

Ignoring the \*\* which I assume should be **...

I guess (we don't know what the split function looks like) that the delimiter parameter is char(1) (or varchar(1)). This means that ** is truncated to *, so you get 3 rows.

gbn
  • 422,506
  • 82
  • 585
  • 676