Ryan Rinaldi

.net development served with a slice of sarcasm
  • rss
  • About Me
  • Blog
  • Contact

Stupid SQL Tricks

Ryan Rinaldi 11/19/2008 4:41:14 AM

Don't ask why I needed this, but here is a SQL function that will abbreviate a string:

create function dbo.fnAbbreviate(@source nvarchar(100))
returns nvarchar(100)
begin
    if charindex(' ', @source) = 0
        return @source
 
    declare @result nvarchar(100)
    declare @i int
    declare @char nvarchar(1)
    set @result = ''
    set @i = 0;
 
    while @i < len(@source)
    begin
        set @char = substring(@source, @i, 1)
        if CONVERT(varbinary, @char) = CONVERT(varbinary, UPPER(@char))
        begin
            set @result = @result + @char
        end
        set @i = @i + 1
    end
    set @result = REPLACE(@result, ' ', '')
    return @result;
end
Comments
No Comments
Tags
blog

Leave a Comment

  • My Tweets

    • Looking at our options to move to TFS 2010 from 08 and change process template: just as painful to migrate off of TFS. sigh.
    • RT @Snywhip: I'm very proud of Spain and it's banning of the bull fights starting in 2012. Finally ;)
    • RT @adamtybor: @sergiopereira happy birthday!
    • Follow Me on Twitter
Powered by Graffiti CMS
  • Content © Ryan Rinaldi 2010
  • design by jide
  • Theme converted to GraffitiCMS by Adonis Bitar