Solved

Proper Case (sentence format)

Posted on 2006-10-21
9
548 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

778 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