April 6, 2007 at 1:43 pm
What function(s) would I be using to get '2006' from '2006-zzzz'? Any help would be greatly appreciated. Thanks.
April 6, 2007 at 2:42 pm
If, in this case, you are always looking for the first 4 characters, use SUBSTRING or LEFT. I would just use substring: substring('2006-zzzz', 1, 4)
April 6, 2007 at 3:26 pm
Thanks Lynn, actually I am looking for a statement that would give me a result before the dash because the number before the dash (-) could vary.
April 6, 2007 at 4:17 pm
Try this:
select substring('2006-zzzz', 1, patindex('%-%', '2006-zzzz') - 1)
You would actually replace the hardcoded string with a variable or column name.
April 9, 2007 at 8:51 am
Thanks Lynn. It worked perfect.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply