|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:07 AM
Points: 6,659,
Visits: 5,682
|
|
Jan Van der Eecken (10/18/2010)
Hi Brandie, I guess the final update back will fail on a database with a case sensitive collation. Shouldn't it rather read: Update idf Set Location = mt1.Location from dbo.Import_Data_Filter idf join dbo.#MyTemp1 mt1 on UPPER(idf.Location) = UPPER(mt1.Location);
Sorry it's been so long since you posted. I was working on massive projects.
Actually, Jan, your code would set everything back to Upper case which is what the customer did NOT want. He wanted Camel Case names.
Brandie Tarvin, MCITP Database Administrator, MCDBA, MCSA
Webpage: http://www.BrandieTarvin.net LiveJournal Blog: http://brandietarvin.livejournal.com/ On LinkedIn!, Google+, and Twitter.
Freelance Writer: Shadowrun Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:07 AM
Points: 6,659,
Visits: 5,682
|
|
Carl Federl (10/18/2010) Perhaps I am missing something but what is wrong with a solution that has no cursors, whiles or UDFs ?
Maybe I'm misreading your solution, but it doesn't seem to account for spaces between names. Such as "St. Augustine". Your solution would make it "St. augustine".
I haven't tested this, though. I'm going off what I see.
Brandie Tarvin, MCITP Database Administrator, MCDBA, MCSA
Webpage: http://www.BrandieTarvin.net LiveJournal Blog: http://brandietarvin.livejournal.com/ On LinkedIn!, Google+, and Twitter.
Freelance Writer: Shadowrun Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:07 AM
Points: 6,659,
Visits: 5,682
|
|
Thanks to everyone who's posted a response. I see I have a lot of testing to do.
Someone mentioned removing extraneous spaces. In this particular case, there are no "extraneous" spaces. The spaces are supposed to be there. We wouldn't want "Little Rock", as in the city from Arkansas, to end up as "Littlerock" or "LittleRock" as that would be bad data. And if there were extraneous spaces, I wouldn't have had to jump through hoops to get them. Just do a REPLACE(location,Space(1),'') and then capitalize the first letter without a looping process.
Still, I appreciate all the input. I do agree that if there are this many solutions to the problem that SQL Server aught to have a proper function for this.
Brandie Tarvin, MCITP Database Administrator, MCDBA, MCSA
Webpage: http://www.BrandieTarvin.net LiveJournal Blog: http://brandietarvin.livejournal.com/ On LinkedIn!, Google+, and Twitter.
Freelance Writer: Shadowrun Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Saturday, June 30, 2012 12:20 PM
Points: 14,
Visits: 63
|
|
Why nobody likes my solution without UDF, WHILEs, Dynamic SQL statments, etc ... :)
Create Table #Import_Data_Filter (MyID Int Identity(1,1) NOT NULL, Location varchar(100))
Insert into #Import_Data_Filter (Location) (Select Lower('Mandarin') UNION ALL Select Lower('San Jose') UNION ALL Select Lower('Baymeadows') UNION ALL Select Lower('My FH Locale') UNION ALL Select Lower('St. Augustine') UNION ALL Select Lower('Test For Three Spaces') UNION ALL Select Lower('Test for being Four Spaces') UNION ALL Select Lower('Test for being Five More Spaces') UNION ALL Select Lower('Baymeadows') UNION ALL Select Lower('St. Augustine'))
update #Import_Data_Filter set location = char(160)+replace(location,' ',char(160)) r: update #import_data_filter set location = replace( location, char(160)+substring(location,charindex(char(160),location)+1,1), ' '+UPPER(substring(location,charindex(char(160),location)+1,1)) ) where charindex(char(160),location)<>0 if @@rowcount>0 goto r
select ltrim(location) from #Import_Data_Filter
drop table #Import_Data_Filter
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:18 AM
Points: 5,618,
Visits: 10,989
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Saturday, June 30, 2012 12:20 PM
Points: 14,
Visits: 63
|
|
| Does that mean that looping through each character is better?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 8:00 AM
Points: 2,266,
Visits: 5,955
|
|
Hi Brandie,
No it would not, it is just in the join that it compares the upper-case version of the camel-cased string to the upper-case version of the original string. If you don't do that on a case-sensitive database, then that join would not return any matches, and no updates would take place at all (assuming that the original and the camel-cased versions to indeed differ).
--------------------------------------------------------------------------
The function of good software is to make the complex appear to be simple. (Grady Booch)
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:18 AM
Points: 5,618,
Visits: 10,989
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Saturday, June 30, 2012 12:20 PM
Points: 14,
Visits: 63
|
|
Now it is clear. Thank you,
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Saturday, June 30, 2012 12:20 PM
Points: 14,
Visits: 63
|
|
Then, here is mine version of UDF:
create function fn_convert_ucase (@s nvarchar(max)) returns nvarchar(max) as begin if @s is null goto ex set @s = char(160)+replace(@s,' ',char(160)) while charindex(char(160),@s)<>0 begin set @s = replace(@s,char(160)+substring(@s,charindex(char(160),@s)+1,1),' '+UPPER(substring(@s,charindex(char(160),@s)+1,1))) end
ex: return @s end
|
|
|
|