Discussion:
Title case SQL excluding conjunctions such as with, and it, is etc...
(too old to reply)
Lee
2011-06-06 16:21:57 UTC
Permalink
Hi

There are lots of functions for title case, but they uppercase the
first letter of each word including conjunctions (with, it, and etc)
which should remain lowercase.

Does anyone have a function which will do this?

Thanks
Lee
Lee
2011-06-08 18:53:58 UTC
Permalink
Post by Lee
Hi
There are lots of functions for title case, but they uppercase the
first letter of each word including conjunctions (with, it, and etc)
which should remain lowercase.
Does anyone have a function which will do this?
Thanks
Lee
Anyone?

Thanks
Bob Barrows
2011-06-08 19:50:18 UTC
Permalink
Post by Lee
Post by Lee
Hi
There are lots of functions for title case, but they uppercase the
first letter of each word including conjunctions (with, it, and etc)
None of those examples are conjunctions (unless you intended "and" to be
part of that list) ... "with" is a preposition; "etc." is an abbreviation
of "et cetera"; "it" is a pronoun. ;-)
Post by Lee
Post by Lee
which should remain lowercase.
I think you meant that short words should remain lowercase. However, this is
not a universal rule, and there are exceptions to that rule. See:
http://www.suite101.com/content/how-to-write-in-title-case-a73866

Not even a word processor like Word gets this "right" (try it and see). And
you expect T-SQL to be able to?
Post by Lee
Post by Lee
Does anyone have a function which will do this?
Anyone?
T-SQL does not really lend itself to this type of task. If you can't do this
formatting in your client application, then you will probably have to resort
to a CLR procedure, which means you should be asking in .Net groups if
anyone has any functions that do this. I don't know of any, but this page,
http://www.llbest.com/?P=75, has a javascript function that does a version
of title-casing that you might find acceptable. View the source and search
it for "function TitleCase" to see how the author did it (he uses a list of
exception words combined with regular expressions).
Erland Sommarskog
2011-06-08 21:32:05 UTC
Permalink
Post by Lee
There are lots of functions for title case, but they uppercase the
first letter of each word including conjunctions (with, it, and etc)
which should remain lowercase.
Does anyone have a function which will do this?
As Bob says, T-SQL is not the best language for this. Or? You could
store all exception words in a table. Hm, no, if you want to do it in
SQL server, do it in the CLR. (If you use a table, I would suggest
slurping the table into a Dictionary.)

The only piece of code I know of for this purpose is the Case and Leading Zero Checker add-on for MediaMonkey:
http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=14822&hilit=case+and+leading+zero+checker

This is quite of a beast written in VBscript.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
Loading...