| Author |
Topic |
|
offspring22
Starting Member
38 Posts |
Posted - 2011-11-30 : 13:27:18
|
| Hello,I have a column with records such as: interior above grade, wall thickness wall thickness, below grade area, interior above grade interior above grade interior above grade, wall thicknessetc.I need to replace the last comma in each (if it has one) with "and" so it reads more like proper grammar.Any suggestions on how to do so? |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-11-30 : 13:44:13
|
| declare @str varchar(100)= 'wall thickness, below grade area, interior above grade'select REVERSE(STUFF(reverse(@str),PATINDEX('%,%',reverse(@str)) ,5,' dna '))JimEveryday I learn something that somebody else already knew |
 |
|
|
offspring22
Starting Member
38 Posts |
Posted - 2011-11-30 : 14:53:28
|
| Hi Jim,The data is being created by the code:replace (replace (replace (replace (replace (replace (replace (replace (replace (replace(RegisteredSizeIncl,'ATTGR', ' attached garage') ,'BALTR', ' balcony/terrace') ,'BLWGR', ' below grade area') ,'DETGR', ' detached garage') ,'IAGR', ' interior above grade') ,'INDPK', ' indoor parking stall') ,'LAND', ' land') ,'OUTPK', ' outdoor parking stall') ,'STORE', ' storage area'),'WT', ' wall thickness')I was hoping for something where I could use that, and have it replace the last comma. I can't seem to get what you have provided to work. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-12-01 : 05:07:22
|
| Try thisselect reverse(stuff(reverse(registeredsizeincl),patindex('%,%',reverse(registeredsizeincl)) ,5,' dna ')) from(select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(registeredsizeincl,'attgr', ' attached garage'),'baltr', ' balcony/terrace'),'blwgr', ' below grade area'),'detgr', ' detached garage'),'iagr', ' interior above grade'),'indpk', ' indoor parking stall'),'land', ' land'),'outpk', ' outdoor parking stall'),'store', ' storage area'),'wt', ' wall thickness') as registeredsizeinclfrom table) as tMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-01 : 05:13:22
|
| i didnt understand why you need so many replaces. better method would be to put these words against their short names in a mapping table and then use it for replacement------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|