Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Proper Case (sentence format)

Posted on 2006-10-21
9
Medium Priority
?
571 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 143

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

885 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