WTF moment: CHARINDEX inside T-SQL returns 0
Date: 11/12/08
(SQL Server) Keywords: sql
T-SQL Code:
[...]
SET @OGCWKT = (SELECT Geometry FROM inserted);
SET @valuesOnly = LEFT(@OGCWKT,LEN(@OGCWKT)-1);
SET @valuesOnly = RIGHT(@valuesOnly,LEN(@valuesOnly)-12);
RAISERROR(N'@valuesOnly = %s',0,0,@valuesOnly);
DECLARE @Index INT;
SET @Index = (SELECT CHARINDEX(@valuesOnly,N','));
RAISERROR(N'charindex of , = %i',0,0,@Index);
[...]
Input:
Geometry = 'LINESTRING (-1.21263269085502 53.1441705273226,-1.21261278851606 53.1441091569917)'
Output:
@valuesOnly = -1.21263269085502 53.1441705273226,-1.21261278851606 53.1441091569917
charindex of , = 0
Msg 536, Level 16, State 5, Procedure InsertEdge, Line 38
Invalid length parameter passed to the SUBSTRING function.
The statement has been terminated.
Source: http://community.livejournal.com/sqlserver/68109.html