Upper case string to Title case conversion

  • Hi Experts,

    Sql server 2k sp3a on Win 2k

    I have to convert a string inot Title case as given below -

    100 RANDOM TEST --> 100 Random Test

    Any help pl.

    Thanks,

    Sheilesh

  • You can do it by utilizing string functions of SQL Server including REPLACE, ASC, CHAR, etc. But the code will be... not pretty and slow. It makes sense to consider doing such translation on the front end if possible. After all, this is a presentation issue so do it in the presentation layer.

    Michael

  • Hi Michael,

    Thanks for the reply. Actually i was looking it to update the tables existing string values - i found one which i am sharing with all , pl. see the URL -

    http://www.winscriptingsolutions.com/Articles/Index.cfm?ArticleID=23124

    Cheers,

    Sheilesh

  • If all values do not require converting, I suggest you use the UDF with a WHERE clause like this:

    
    
    UPDATE MyTable
    SET MyCharCol = dbo.udf_Proper(MyCharCol)
    WHERE CAST(MyCharCol AS varbinary(8000)) <> CAST(dbo.udf_Proper(MyCharCol) AS varbinary(8000))

    This can be faster as it will prevent unnecessary updating and logging.

    --Jonathan



    --Jonathan

  • Hi,

    Well I did the same in my database.

    If u want to perform this on every insert then it will be very tedious as it will require a lots of processing. If u want to perform the action on already inserted values then try using a cursor and String functions.

    Mail me at gauravgupta@adventmatrixinc.com for the code.


    .........

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply