September 24, 2008 at 1:40 pm
I am trying to pull a field where if the data value has 8 characters, strip off the first and last character. If data value has 6 characters, leave as is. The data type for this field is varchar(20).
Can anyone help me, I need to get this report out to our Business Analyst.
Thanks!
September 24, 2008 at 2:15 pm
a combination of using substring and a where statement will do the job; you might need to tweak the WHERE statemtn...are you sure it's only items that are exactly 8 chracters, or also greater than 8?
Select substring(columnname,2,6)
where len(columnname) = 8
Lowell
September 24, 2008 at 2:29 pm
Erin
I am trying to pull a field where if the data value has 8 characters, strip off the first and last character. If data value has 6 characters, leave as is.
Not to be picky, but what should be done if the data length is 7 characters or is that some how or other not possible due to other filtering of the input data by a user application, or prior T-SQL ? Also see Lowell's question about more than 8 characters in length.
September 25, 2008 at 8:38 am
I was told the software use to allow up to 8 characters. However, it was changed from 8 to 6. But you bring up a good point. I need a more dynamic way to pull this field's characters.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply