title: SubString and CharIndex in sql join
body: <pre><code>DECLARE @TABLE_A TABLE  (ID INT,NAME_A VARCHAR(100),VAL INT)
  INSERT INTO @TABLE_A VALUES(1,'1-06-734-01791/01',900),(2,'NAME2/2/F',100),(3,'NAME3/3',400),(4,'NAME44',80)
  
  DECLARE @TABLE_B TABLE (ID INT,NAME_B VARCHAR(100))
  INSERT INTO @TABLE_B VALUES(1,'1-06-734-01791'),(2,'NAME2'),(3,'NAME3'),(4,'NAME4')
  
  SELECT A.ID,b.NAME_b,A.VAL FROM @TABLE_A AS A
       INNER JOIN @TABLE_B AS B 
     ON B.NAME_B=SUBSTRING( A.NAME_A,1,CHARINDEX('/',A.NAME_A,1)-1)  
  </code></pre>
  
  <p>This gives the following error:</p>
  
  <blockquote>
    <p>Invalid length parameter passed to the LEFT or SUBSTRING function.</p>
  </blockquote>
  
  <p>In <code>join</code> section I don't want <code>like</code> operator because it will return more data.</p>