MS SQL substring a character
Posted on 2008-10-07
I viewed searched and found one of the questions that pertains to my issue "MS SQL substring a character" The response did not work for me however i was hoping to get more assistance with a similar issue.
I am looking to pull the characters that happen on the left side of the first ':' for instance i could have data that looks like 12:31:01 or 13:20 or 1:00 or 3:00:09:00
In all of these cases i would like to pull out and use the 12,13,1, and 3
The code i attempted to modify was
substring(ltrim(rtrim(field)), 1, Charindex('$', ltrim(rtrim(field)))
I modified it to look like this:
substring(ltrim(rtrim([Time])), 1, Charindex(':', ltrim(rtrim([time])))
in which i received an error invalid or missing Expression.