Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mkool
Starting Member
25 Posts |
Posted - 2008-03-13 : 13:07:53
|
| i have one table called Healthmanagementin that i have column HealthTitles in that there r so many rows..few of them r here:HealthTitles---------------------------------Lung HealthLung Health: GeneralLung Health: Asperic Detailed ModifiedDiseasesDiseases: in one generationAttacksAttacks: Health Relatedi want in ouput all rows but which r with ':' i want after that part only and if the rows r without ':' then remain as it is:so i wantHealthTitles---------------------------------Lung HealthGeneralAsperic Detailed ModifiedDiseasesin one generationAttacksHealth Relatedhow can i get that?thanks for any help. |
|
|
mkool
Starting Member
25 Posts |
Posted - 2008-03-13 : 13:25:10
|
| i tried like:Select substring([HealthTitles],1,charindex(':',[HealthTitles])+1) as HealthTitles FROM Healthmanagementbut i m gettingHealthTitles---------------------------------Lung HealthLung Health: Lung Health: DiseasesDiseases: AttacksAttacks: |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-03-13 : 13:27:17
|
| DECLARE @table TABLE (Disease varchar(100))INSERT INTO @TABLESELECT 'Lung Health'UNION ALLSELECT 'Lung Health: General'UNION ALLSELECT 'Lung Health: Asperic Detailed Modified'UNION ALLSELECT 'Diseases'UNION ALLSELECT 'Diseases: in one generation'UNION ALLSELECT 'Attacks'UNION ALLSELECT 'Attacks: Health Related'SELECT CASE WHEN Disease like '%:%' THEN LTRIM(SUBSTRING(Disease,PATINDEX('%:%',disease)+1,500)) ELSE Disease ENDFROM @tableJim |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-03-13 : 13:29:25
|
One more version :)DECLARE @Healthmanagement TABLE (HealthTitles VARCHAR(50))INSERT @HealthmanagementSELECT 'Lung Health'UNION ALL SELECT 'Lung Health: General'UNION ALL SELECT 'Lung Health: Asperic Detailed Modified'UNION ALL SELECT 'Diseases'UNION ALL SELECT 'Diseases: in one generation'UNION ALL SELECT 'Attacks'UNION ALL SELECT 'Attacks: Health Related'SELECT CASE WHEN HealthTitles LIKE '%:%' THEN RIGHT(HealthTitles, LEN(HealthTitles) - (CHARINDEX(':', HealthTitles) + 1)) ELSE HealthTitles END AS HealthTitlesFROM @Healthmanagement |
 |
|
|
mkool
Starting Member
25 Posts |
Posted - 2008-03-13 : 13:44:23
|
| thanks Lamprey and jimf..both of you thanks..got both way correct results.thanks. |
 |
|
|
|
|
|