| Author |
Topic |
|
vidhya
Posting Yak Master
108 Posts |
Posted - 2008-07-17 : 08:56:37
|
| Hi,Thanks for that reply, i have executed using ur solution but it trims the next word also actually i don't want that.for egthe actual column value is Grand xxGrand DTOGrand PBTCelio4Runner ltd4Runner sdAvalon XLCorolla DeluxeMarkExtra long Double after using ur solution the result isGrandCelio4Runner AvalonCorolla MarkExtra wat i need is?if the column contains the values asGrand xxGrand DTOGrand PBTCelio4Runner ltd4Runner sdAvalon XLCorolla DeluxeMarkExtra long Doublei like to get the result asGrand Celio4Runner Avalon XLCorolla DeluxeMarkExtra long Doublewat to do? |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-17 : 08:58:37
|
| so not just the first word then ?by what logic do you include Avalon XLCorolla DeluxeExtra Long Doublein your result set?Em |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-17 : 08:58:44
|
How do you decide to get the whole string or only the 1st word ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
|
|
vidhya
Posting Yak Master
108 Posts |
Posted - 2008-07-17 : 09:08:40
|
quote: Originally posted by elancaster so not just the first word then ?by what logic do you include Avalon XLCorolla DeluxeExtra Long Doublein your result set?Em
Hi,Avalon XL ,Corollo deluxe,Grand xx it's all model name.so, if it finds the same model name like Grand xx, Grand TT it should display it as Grand. that's it. |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-17 : 09:09:43
|
| so... only strip it back to 1st word if it appears more than once in the table?Em |
 |
|
|
vidhya
Posting Yak Master
108 Posts |
Posted - 2008-07-17 : 09:20:20
|
quote: Originally posted by elancaster so... only strip it back to 1st word if it appears more than once in the table?Em
s s s |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-17 : 09:33:17
|
quote: Originally posted by vidhya s s s
what do you mean by s s s ? ? ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-17 : 09:35:52
|
quote: Originally posted by vidhya
quote: Originally posted by elancaster so not just the first word then ?by what logic do you include Avalon XLCorolla DeluxeExtra Long Doublein your result set?Em
Hi,Avalon XL ,Corollo deluxe,Grand xx it's all model name.so, if it finds the same model name like Grand xx, Grand TT it should display it as Grand. that's it.
You should use two columns Grand and model to avoid any confusionsMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-17 : 09:36:30
|
quote: Originally posted by khtan
quote: Originally posted by vidhya s s s
what do you mean by s s s ? ? ? KH[spoiler]Time is always against us[/spoiler]
Chat language yes yes yesMadhivananFailing to plan is Planning to fail |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-17 : 09:37:11
|
quote: Originally posted by madhivanan
quote: Originally posted by khtan
quote: Originally posted by vidhya s s s
what do you mean by s s s ? ? ? KH[spoiler]Time is always against us[/spoiler]
Chat language yes yes yesMadhivananFailing to plan is Planning to fail
i feel so old Em |
 |
|
|
vidhya
Posting Yak Master
108 Posts |
Posted - 2008-07-17 : 09:37:33
|
| Actually, i replied for that before ans that's y i said it.For my queryIf the 1st word of the column value appears more than once then it should be removed. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-17 : 09:46:38
|
quote: Originally posted by elancaster
quote: Originally posted by madhivanan
quote: Originally posted by khtan
quote: Originally posted by vidhya s s s
what do you mean by s s s ? ? ? KH[spoiler]Time is always against us[/spoiler]
Chat language yes yes yesMadhivananFailing to plan is Planning to fail
i feel so old Em
me too   KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-17 : 09:47:23
|
quote: Originally posted by vidhya Actually, i replied for that before ans that's y i said it.For my queryIf the 1st word of the column value appears more than once then it should be removed.
declare @t table(data varchar(100))insert into @tselect 'Grand xx' as data union allselect 'Grand DTO' as data union allselect 'Grand PBT' as data union allselect 'Corolla Deluxe' as data union allselect 'Mark' union allselect '4Runner ltd'select distinct case when t2.counting>1 then t2.data else t1.data end as data from @t t1inner join( select rtrim(left(data,charindex(' ',data + ' ',1))) as data, count(*) as counting from @t group by rtrim(left(data,charindex(' ',data + ' ',1))) ) as t2 on t1.data like t2.data+'%'However consider my suggestion of using two different columns MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-17 : 09:55:04
|
[code]DECLARE @TABLE TABLE( col varchar(20))INSERT INTO @TABLESELECT 'Grand xx' UNION ALLSELECT 'Grand DTO' UNION ALLSELECT 'Grand PBT' UNION ALLSELECT 'Celio' UNION ALLSELECT '4Runner ltd' UNION ALLSELECT '4Runner sd' UNION ALLSELECT 'Avalon XL' UNION ALLSELECT 'Corolla Deluxe' UNION ALLSELECT 'Mark' UNION ALLSELECT 'Extra long Double';WITH yak(col, word)AS( SELECT col, word = CASE WHEN CHARINDEX(' ', col) <> 0 THEN left(col, CHARINDEX(' ', col) - 1) ELSE col END FROM @TABLE)SELECT word = coalesce(y.col, d.word)FROM ( SELECT word, cnt = COUNT(*) FROM yak GROUP BY word ) d left JOIN yak y ON y.word = d.word AND d.cnt = 1ORDER BY word/*word -------------------- 4RunnerAvalon XLCelioCorolla DeluxeExtra long DoubleGrandMark(7 row(s) affected)*/[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-17 : 09:56:28
|
prob not the best but my version too...declare @t table (col varchar(30))insert into @tselect 'Grand xx' union all select 'Grand DTO'union all select 'Grand PBT'union all select 'Celio'union all select '4Runner ltd'union all select '4Runner sd'union all select 'Avalon XL'union all select 'Corolla Deluxe'union all select 'Mark'union all select 'Extra long Double'select distinct case when left(Col,charindex(' ',Col+' ',1)) IN (select left(Col,charindex(' ',Col+' ',1)) from @t group by left(Col,charindex(' ',Col+' ',1)) having COUNT(*) =1) then COL else left(Col,charindex(' ',Col+' ',1)) endfrom @tEm |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-17 : 09:57:51
|
yeah . . i am getting old KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|