Custom user-defined string functions by Igor Nikiforov
Serdar Yegulalp, Contributor
Montreal-based SQL Server programmer Igor Nikiforov has written a number of useful Transact-SQL custom string manipulation functions that can be put to work in a variety of database projects. Many of these functions would normally be performed by business logic (for instance, in an Active Server Page), but including them as user functions in SQL opens up a broad range of possible programming tricks.
Some of the functions in this package include:
GETWORDCOUNT(): Counts the number of words in a string. Optionally, a user can specify a delimiter character if a space is not being used; the default delimiters are space, tab, carriage return and line feed.
Premium Access
Register now for unlimited access to our premium content across our network of over 70 information Technology web sites.
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy
Dig Deeper
-
People who read this also read...
This was first published in May 2005
GETWORDNUM(): Returns a specified word from a string -- i.e., fifth word -- with user-specifiable delimiters.
OCCURS(): Counts the number of occurrences of a character expression within another character expression.
AT() / RAT(): Returns the numeric position of the leftmost or rightmost occurrence of a character string within another character string.
PROPER(): Formats a string in name-capitalization format -- i.e., only the first letter of each word is capitalized.
ARABTOROMAN(): Converts conventional Arabic numerals in a numeric expression to a Roman character string. The reverse can be done through ROMANTOARAB(), also included.
PADL(), PADR(), PADC(): Returns a string from an expression which is padded with spaces or characters to a specified length either on the left, right or both sides, respectively.
RCHARINDEX(): Similar to the existing CHARINDEX() function in SQL Server, but works from right to left instead of left to right.
Keep in mind that user-defined functions in very large views or long-running stored procedures can significantly impact performance. The best time to use a function like that would be when you are generating results to be stored in a table.
Serdar Yegulalp is editor of the Windows Power Users Newsletter. Check it out for the latest advice and musings on the world of Windows network administrators -- and please share your thoughts as well!
Disclaimer:
Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.
Join the conversationComment
Share
Comments
Results
Contribute to the conversation