April 12, 2006 at 12:13 am
April 12, 2006 at 4:56 am
Hi Karthik,
It's hard to understand what you're asking for, but maybe it's this...
--data
declare @t table (words varchar(100))
insert @t
select 'hello, thanks, movies, tickets'
union all select 'abc, de, fghi'
union all select 'xyz'
--calculation
while exists (select * from @t where words is not null)
begin
update @t set words = case when not charindex(',', words) = 0
then left(words, len(words) - charindex(',', reverse(words))) end
select * from @t
end
If not, please provide an example with the output(s) you are hoping to get. ![]()
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
April 12, 2006 at 8:11 am
SELECT
LTRIM(SUBSTRING(',' + t.words + ',', n.number + 1,
CHARINDEX(',', ',' + t.words + ',', n.number + 1) - n.number - 1))
FROM [numbers] n
INNER JOIN @t t
ON SUBSTRING(',' + t.words + ',', n.number, 1) = ','
AND n.number < LEN(',' + t.words + ',')
Will need to create numbers table containing numbers from 1 to max len of column
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply