Solved

Proper Case (sentence format)

Posted on 2006-10-21
9
546 Views
Last Modified: 2012-08-13
Hello, I have a table with rows of data formated in various cases. Example: "THis is A hAppy Cat. sometimes This cat is Unhappy."

I would like to use a function in a query that can turn it into "This is a happy cat. Somtimes this cat is unhappy."

I do not want to capitalize the first letter of every word, however only the first letter of the first word in each sentence for proper formating.

Thanks for your help on this.

Ron
0
Comment
Question by:ronyak
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17781554
0
 

Author Comment

by:ronyak
ID: 17781738
I do not want to capitalize the first letter of every word, however only the first letter of the first word in each sentence for proper formating.
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17781808
Hi ronyak,

You should be able to derive some of the required logic from that function. However, I have to ask why you would want to do this in T-SQL. T-SQL is great for set-based operations, but string manipulation is NOT it's strongest point (and is resource intensive). That is best left to client applications.

The CLR (.NET) is a good start - there are lot's of examples of tokenisers out on the net (our very own gregoryyoung has a good example of a high performance tokeniser at http://codebetter.com/blogs/gregyoung/archive/2006/08/15/148292.aspx - true, a simple word count but can eaasily be adapted for your requirements). I would suggest validating the input before allowing it into SQL Server. Once you have the base code, you can always code a seperate application to clean up your history.
0
 

Author Comment

by:ronyak
ID: 17781890
Thx, i'm not very experienced besides MS Access and basic SQL, i was hoping for a function i could put in a query like the propercase function on the link above.. I have a dts package that exports to a text file and this query cleans up the data before export..
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 29

Expert Comment

by:Nightman
ID: 17781904
Look, you CAN do this in T-SQL. But just because you can doesn't mean it's a good idea (Tex Johnstone barrel-rolled a Boeing 707 in 1955 - just because you can doesn'tmean that you should!)

Performing that kind of operation in T-SQL with more than a few rows is a server killer.

Either clean up on the way in, or at the least have some kind of batch process that cleans up the data in SQL on a regular basis (off-peak, maintenance task when no-one is really hitting the server).
0
 
LVL 39

Expert Comment

by:appari
ID: 17782407
try like this, In this function sentence separator is supposed as '. ' . you may be required to change the function to handle '.'

Alter Function Propercase(@srcVal varchar(2000)) returns varchar(2000)
as
begin
      declare @temp varchar(2000)
      declare @curPos int
      select @temp = lower(@srcVal), @curPos=0
      select @temp = upper(substring(@temp,1,1)) + substring(@temp,2,len(@temp)-1)
      while charindex('. ',@temp,@curPos+1)<>0
      begin
            select @curPos = charindex('. ',@temp)
            select @temp = substring(@temp,1,@curPos+1) +
                                          upper(substring(@temp,@curPos+2,1)) +
                                          substring(@temp,@curPos+3,len(@temp)-@curPos-2)
      end

      return @temp
end


select dbo.Propercase('THis is A hAppy Cat. sometimes This cat is Unhappy')
0
 

Author Comment

by:ronyak
ID: 17807137
I tried running the function but i keep getting timeout expired..

ideas?
0
 
LVL 39

Accepted Solution

by:
appari earned 125 total points
ID: 17807232
small miss in the unction, try this

Alter Function Propercase(@srcVal varchar(2000)) returns varchar(2000)
as
begin
     declare @temp varchar(2000)
     declare @curPos int
     select @temp = lower(@srcVal), @curPos=0
     select @temp = upper(substring(@temp,1,1)) + substring(@temp,2,len(@temp)-1)
     while charindex('. ',@temp,@curPos+1)<>0
     begin
          select @curPos = charindex('. ',@temp,@curPos+1)
          select @temp = substring(@temp,1,@curPos+1) +
                                   upper(substring(@temp,@curPos+2,1)) +
                                   substring(@temp,@curPos+3,len(@temp)-@curPos-2)
     end

     return @temp
end
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now