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 |
|
polygonSQL
Starting Member
8 Posts |
Posted - 2005-01-28 : 06:22:24
|
| Is their any command to make a row that = 'GREEN BAY' = 'Green Bay'? I've made this script for all my cities that are one word:-----------------------update patientsset patcity = ( select top 1 left(patcity, 1) + right(patcity, (datalength(patcity) - 1)) from patients S where S.patid = P.patid )from patients Pwhere patcity not like '% %'-----------------------but how would I do it for cities that have 2 or three words?select * from end_userwhere clue > 0GO( 0 rows returned ) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-01-28 : 07:05:13
|
| Try thisDeclare @t table(n varchar(100))insert into @t values('GREEN BAY')Select left(n,1)+lower(substring(n,2,charindex(' ',n)-1))+ substring(n,charindex(' ',n),2)+lower(substring(n,charindex(' ',n)+2,len(n))) from @tMadhivanan |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
|
|
polygonSQL
Starting Member
8 Posts |
Posted - 2005-01-28 : 18:46:21
|
quote: Originally posted by madhivanan Try thisDeclare @t table(n varchar(100))insert into @t values('GREEN BAY')Select left(n,1)+lower(substring(n,2,charindex(' ',n)-1))+ substring(n,charindex(' ',n),2)+lower(substring(n,charindex(' ',n)+2,len(n))) from @tMadhivanan
Genius pure genius, I haven't had the time to break this down, but I tested it and I think it will work for my purpose. |
 |
|
|
polygonSQL
Starting Member
8 Posts |
Posted - 2005-01-28 : 18:51:16
|
quote: Originally posted by Seventhnight Read through this:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=40338Corey "If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
OOoooo oooh ooh, it's like crack err I mean a candy store and I'm in it. Johnny 5 -- Input, input, input!-----------------------select * from end_userwhere clue > 0GO( 0 rows returned ) |
 |
|
|
polygonSQL
Starting Member
8 Posts |
Posted - 2005-01-29 : 19:44:02
|
| Thanks Seventhnight!fyi this is the script I usedI changed len to datalength because if the field read 'GREEN BAY ' there would be problemsDeclare @table table (oldcity varchar(1000), newcity varchar(1000), pos int default(-1))Insert Into @table (oldcity)Select patcity from patientsUpdate @table Set newcity = upper(left(oldcity,1)) + right(lower(oldcity),datalength(oldcity)-1) From @tableDeclare @pos intwhile exists(Select * From @table Where pos<>0)Begin Update @Table Set newcity = case when pos>0 then left(newcity,pos) + upper(substring(newcity,pos+1,1)) + right(newcity,datalength(newcity)-pos-1) else newcity end, pos = case when patindex('%[^a-z][a-z]%',right(newcity,datalength(newcity)-pos))>0 then patindex('%[^a-z][a-z]%',right(newcity,datalength(newcity)-pos)) + case when pos=-1 then 0 else pos end else 0 end From @Table Where pos<>0EndUpdate patientsSet patcity = (select top 1 newcity from @table where oldcity = patients.patcity)-----------------------select * from end_userwhere clue > 0GO( 0 rows returned ) |
 |
|
|
|
|
|
|
|