I have a large SQL table which has an `ItemID` column and a `Value` column ; the column `Value` contains a date which I want to extract.

This query works fine and returns the date:

```
declare @Value varchar(255)
set @Value = 'Item-Id: 1243223  Date: 5 Oct 2003 1:14:53  From: xx@yahoo.com  To: yy@yahoo.com'
select substring(@Value,CharIndex(' Date: ',@Value) + 7,charindex(' From: ',@Value)-CharIndex(' Date: ',@Value) -7)

```

My question is: how can I run this query on my entire table without using a "declare"?

Something like:

```
select substring(Value, CharIndex(' Date: ', Value) + 7, charindex(' From: ',Value)  - CharIndex(' Date: ', Value) - 7) 
from TableName 

```

If I run this query, I get this error: 

> 
> Invalid length parameter passed to the SUBSTRING function.
> 
> 
>