truncation

  • What function(s) would I be using to get '2006' from '2006-zzzz'?  Any help would be greatly appreciated. Thanks.

  • 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)

     

  • 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.

  • Try this:

    select substring('2006-zzzz', 1, patindex('%-%', '2006-zzzz') - 1)

    You would actually replace the hardcoded string with a variable or column name.

  • 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