Phil Factor's Phrenetic Phoughts

Simple-Talk columnist
The wilder shores of Transact SQL

The TSQL of Verticons and Anime Emoticons

Published Tuesday, January 09, 2007 11:12 PM

Well there I was trying to think of an idea for a blog (u_u) when it suddenly occurred to me (*_*) that I should do a nice little SQL function on Emoticons. It was a happy thought (^_^) which made me smile (n_n). I was amazed (^.^) and astonished (*^*) sometimes incredulous (o_O) at the variety of manga emoticon (verticon) around. Call me an old fool if you like, (>x<!) but I think they're cool!

I'd never felt the need to add emoticons to my writing (ñ_ñ). My problem is in remembering them (O_O). I get a bit confused by them. (p_q) However, I now find them enormously useful *(^O^)* as many people who use english as a second language find my irony, sarcasm, hyperbole and invective entirely incomprehensible. (-_-;) I suspect the other bloggers will be jealous 8(>_<)8 at my new cool powers of communication (ò_ó) I was a bit apprehensive (._.) about the time it would take to write a function to interpret them

True enough, typing them in sas boring (=_=). At one point, I felt sleepy (z_z) and I must have dozed off (-_-) at the keyboard m(_ _)m. I woke up with an inprint of the keyboard on my forehead.(X_X) Glancing around \\(<.<|>.>)// I realise I'd still not finished the blog entry (>_<) which made me cross (ò_ó). Oh dear, no blog entry (._.) and the editor would be cross (¬_¬") mad (ò_ó) or angry (>x<!). My readers would, on the other hand, be sad (T_T), possibly even crying (;_;). Well, certainly one or two might be miserable (!_!)

Oh dear, better get on with it (-_-;). Actually it wasn't too hard w(^o^)W, after one got over the initial shock (/_\) so here it is finished (^_~). (^o^)y

SET ANSI_NULLS ON

SET 
QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[ufsMangaMeaning]

@Emoticon NVARCHAR(80)


RETURNS NVARCHAR(20AS 
BEGIN 

RETURN
       
CASE @emoticon 
               
WHEN '(^_^)' THEN 'happy'
               
WHEN '(u_u)' THEN 'exasperated'
               
WHEN '(*_*)' THEN 'euphoric'
               
WHEN '(O_O)' THEN 'shocked'
               
WHEN '(^_~)' THEN 'winking'
               
WHEN '(^.^)' THEN 'amazed'
               
WHEN '(n_n)' THEN 'smiling'
               
WHEN '(._.)' THEN 'apprehensive'
               
WHEN '(-_-)' THEN 'sleeping'
               
WHEN '(;_;)' THEN 'crying'
               
WHEN '(T_T)' THEN 'sad' 
               
WHEN '(@_@)' THEN 'dizzy'
               
WHEN '(O_O)' THEN 'amazed' 
               
WHEN '(*^*)' THEN 'astonished'
               
WHEN '(>_<)' THEN 'pained'
               
WHEN '(^o^)' THEN 'glad'
               
WHEN '*(^O^)*' THEN 'happier' 
               
WHEN '(¬_¬)' THEN 'angry'
               
WHEN '(¬_¬")' THEN 'pissed off' 
               
WHEN '(X_X)' THEN 'dead' 
               
WHEN '(=_=)' THEN 'bored'
               
WHEN '(*-*)' THEN 'pleased'
               
WHEN '(!_!)' THEN 'miserable'
               
WHEN '(o_O)' THEN 'incredulous'
               
WHEN '(*O*)' THEN 'amazed' 
               
WHEN '(-O-)' THEN 'pretentious'
               
WHEN '([o])' THEN 'crying'
               
WHEN '\(<.<|>.>)//' THEN 'Glancing around'
               
WHEN '([-])' THEN 'crying'
               
WHEN '(p_q)' THEN 'confused'
               
WHEN '(o_o)' THEN 'seriously?'
               
WHEN '(;O;)' THEN 'weeping'
               
WHEN '(_O_)' THEN 'exasperated' 
               
WHEN '(.O.'')' THEN 'confused' 
               
WHEN '(-_-;)' THEN 'contrite' --'i messed it up' 
               
WHEN '(''_'')' THEN 'serious'
               
WHEN '(?_?)' THEN 'puzzled'
               
WHEN '(''O'')' THEN 'singing'
               
WHEN 'm(_ _)m' THEN 'sleeping on the desk' 
               
WHEN 'w(^o^)W' THEN 'wow' 
               
WHEN '(/_\)' THEN 'dispairing' 
               
WHEN '(=^_^=)' THEN 'cattish' 
               
WHEN '(u_u)' THEN 'low'
               
WHEN '(Ú_Ú)' THEN 'depressed' 
               
WHEN '(>x<!)' THEN 'furious' 
               
WHEN '(*¬*)' THEN 'drooling'
               
WHEN '(Ñ_Ñ)' THEN 'insincere'  
               
WHEN '(Y_Y)' THEN 'infinite sadness' 
               
WHEN '($_$)' THEN 'aquisitive'
               
WHEN '(Ò_Ó)' THEN 'mad'
               
WHEN '(?_?)' THEN 'amorous' 
               
WHEN '(xOx)' THEN 'dispairing'  
               
WHEN '(>O<)' THEN 'revolted'
               
WHEN '(-_o)' THEN 'winking'
               
WHEN '8(>_<)8' THEN 'jealous'
               
WHEN '(z_z)' THEN 'sleepy' 
               
WHEN '(^o^)y' THEN 'congratulatory' 
       
ELSE @emoticon
       
END
END
--select dbo.ufsMangaMeaning('8(>_<)8')
GO
CREATE function [dbo].[ufsMangaEmoticon]

@Emotion NVARCHAR(80)


RETURNS NVARCHAR(20AS 
BEGIN 

RETURN
       
CASE @emotion 
WHEN   'happy' THEN'(^_^)'
               
WHEN 'exasperated' THEN '(u_u)' 
               
WHEN 'euphoric' THEN '(*_*)'
               
WHEN 'shocked' THEN '(O_O)'
               
WHEN 'winking' THEN '(^_~)' 
               
WHEN 'amazed' THEN '(^.^)' 
               
WHEN 'smiling' THEN '(n_n)' 
               
WHEN 'apprehensive' THEN '(._.)' 
               
WHEN 'sleeping' THEN '(-_-)' 
               
WHEN 'crying' THEN '(;_;)'
               
WHEN 'sad'  THEN '(T_T)'
               
WHEN 'dizzy' THEN '(@_@)'
               
WHEN 'amazed' THEN '(O_O)'  
               
WHEN 'astonished' THEN '(*^*)'
               
WHEN 'pained' THEN '(>_<)'
               
WHEN 'glad' THEN '(^o^)' 
               
WHEN 'happier' THEN '*(^O^)*'
               
WHEN 'angry' THEN '(¬_¬)'
               
WHEN 'pissedOff' THEN '(¬_¬")'
               
WHEN 'dead' THEN '(X_X)'
               
WHEN 'bored' THEN '(=_=)'
               
WHEN 'pleased' THEN '(*-*)'
               
WHEN 'miserable' THEN '(!_!)'  
               
WHEN 'incredulous' THEN '(o_O)'
               
WHEN 'amazed' THEN '(*O*)' 
               
WHEN 'pretentious' THEN '(-O-)' 
               
WHEN 'crying' THEN '([o])'
               
WHEN 'GlancingAround' THEN '\(<.<|>.>)//'
               
WHEN 'crying' THEN '([-])'
               
WHEN 'confused' THEN '(p_q)'
               
WHEN 'seriously?' THEN '(o_o)'  
               
WHEN 'weeping' THEN '(;O;)'
               
WHEN 'exasperated' THEN '(_O_)'
               
WHEN 'confused' THEN '(.O.'')' 
               
WHEN 'contrite' THEN '(-_-;)' --'i messed it up' 
               
WHEN 'serious' THEN '(''_'')'
               
WHEN 'puzzled' THEN '(?_?)'
               
WHEN 'singing' THEN '(''O'')'
               
WHEN 'sleepingOnTheDesk' THEN 'm(_ _)m' 
               
WHEN 'wow' THEN 'w(^o^)W'
               
WHEN 'dispairing' THEN '(/_\)' 
               
WHEN 'cattish' THEN '(=^_^=)'
               
WHEN 'low' THEN '(u_u)'
               
WHEN 'depressed' THEN '(Ú_Ú)'
               
WHEN 'furious' THEN '(>x<!)'
               
WHEN 'drooling' THEN '(*¬*)'
               
WHEN 'insincere'  THEN '(Ñ_Ñ)'
               
WHEN 'infinitly sad' THEN '(Y_Y)'
               
WHEN 'aquisitive' THEN '($_$)'
               
WHEN 'mad' THEN '(Ò_Ó)' 
               
WHEN 'amorous' THEN '(?_?)'
               
WHEN 'dispairing'  THEN '(xOx)'
               
WHEN 'revolted' THEN '(>O<)'
               
WHEN 'winking' THEN '(-_o)'
               
WHEN 'jealous' THEN '8(>_<)8' 
               
WHEN 'sleepy' THEN '(z_z)' 
               
WHEN 'congratulating' THEN '(^o^)y'
       
ELSE @emotion
       
END
END
--select dbo.ufsMangaMeaning('8(>_<)8')

GO


CREATE function [dbo].[ufsEmotify]

@String NVARCHAR(4000),
@prefix VARCHAR(80)='',
@suffix VARCHAR(80)=''

/*
*/

RETURNS NVARCHAR(4000AS 
BEGIN 
DECLARE 
@Where INT
DECLARE 
@len INT

WHILE 

       
BEGIN 
       SELECT 
@where=CHARINDEX'#'ISNULL(@String,'') )
       
--If we are out of % placeholders return the @String 
       
IF @where BREAK 
       SELECT 
@lenPATINDEX('%[^a-z]%'SUBSTRING(@String,@Where+2,4000)+'*')
       
SELECT @String 
               
STUFF@String@where@len+1
               
@Prefix
               
+dbo.ufsMangaEmoticon(SUBSTRING(@String,@where+1,@len))
               +
@Suffix)
       
END 
RETURN 
(@String
END 
GO

SELECT dbo.ufsEmotify('<p>Well there I was trying to think of an idea 
for a blog #exasperated when it suddenly occurred to me #euphoric that
 I should do a nice little SQL Function on Emoticons. It was a happy thought
#happy which made me smile #smiling. I was amazed #amazed and astonished 
#astonished  sometimes incredulous #incredulous at the variety of emoticon.
</p><p>I''d never felt the need to add emoticons to my writing #insincere. 
My problem is in remembering them #shocked. I get a bit confused by them. 
#confused However, I now find them enormously useful #happier as many people
who use english as a second language find my irony, sarcasm, hyperbole 
and invective entirely incomprehensible. #contrite I suspect the other 
bloggers will be jealous #jealous at my new cool powers of communication #mad
I was a bit apprehensive #apprehensive about the time it would take to write 
a function to interpret them</p><p>True enough, typing them in sas boring 
#bored. At one point, I felt sleepy #sleepy  and I must have dozed off 
#sleeping at the keyboard #sleepingonthedesk. I woke up with an inprint 
of the keyboard on my forehead.#dead Glancing around #Glancingaround I 
realise I''d still not finished the blog entry #pained which made me cross
#mad. Oh dear, no blog entry #apprehensive and the editor would be cross 
#pissedoff mad #mad or angry #furious. My readers would, on the other hand,
be sad #sad, possibly even crying #crying. Well, certainly one or two might
 be miserable #miserable </p><p>Oh dear, better get on with it #contrite. 
Actually it wasn''t too hard #wow, after one got over the initial shock 
#dispairing so here it is finished #winking. #congratulating </p>'
'<font
 size="2" face="Courier New" color="Green">'
,'</font>')

Comments

 

CalmYourself said:

I am pleased (*-*) by the idea, very creative (^o^)y  Small suggestion, would it not have been better to store the relationship between the english word and the verticon in a table rather than hardcode it in a case statement?

This would enable you to add/change the verticons for various words as the community feels the need to change them.  Any obvious downsides to this approach that I should be seeing?
January 10, 2007 12:05 AM
 

Phil Factor said:

(-_-;)  I suspect that you are absolutely right.  (u_u)  It should be. When I first wrote it, I didn't realise how many emoticons there were.  (^.^),  and it is always more convenient to restrict the number of database objects when publishing code samples. (-_o)
Actually, I don't use the ufsMangaMeaning function at all. I just added it so one can look up what a verticon means.
Having said that,  (''_'')  what are the performance issues? (?_?)  Obviously, the code in this Blog is very fast, and I'd be curious to know at what point it is sensible to use an indexed table to store the Manga Emoticons.  (p_q)  Because it is less costly to table-scan small tables, I suspect that I haven't yet reached the point where it would make sense to have an emoticon table from the performance viewpoint.
However, if someone out there would like to build one, I'd be delighted to add it to this Blog
January 10, 2007 3:03 AM
 

WilliamGrene said:

(^o^)y
January 10, 2007 12:19 PM
 

Neil Davidson said:

Phil,

As always

:-

- Neil
January 22, 2007 9:31 AM
 

Karen said:

I'm {:-8-< a happy gal to find all these emoticons...
January 25, 2007 3:19 PM
 

Phil Factor said:

What about my splendid  idea for an emotional teddy bear. This is a function, and you can see some of the output below

       (.) (.)
       ( ^ ^ )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ¬ ¬ )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( X X )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( = = )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ! ! )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 

       (.) (.)
       ( o O )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( p q )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( o o )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ' ' )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ? ? )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( / \ )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( u u )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ú ú )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ñ ñ )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( Y Y )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( $ $ )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ò ó )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( ? ? )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 


       (.) (.)
       ( z z )
        \ * /
      / .   . \
     { }     { }
       |     |    
      ( }- -{ } 

And here is the source and some examples of its use

ALTER  function [dbo].[ufsEmotionalTeddy]

(
@Emotion NVARCHAR(80)
)

RETURNS NVARCHAR(255) AS
BEGIN

RETURN
STUFF('
(.) (.)
( * * )
\ * /
/ . . \'
+'
{ } { }
| |
( }- -{ }
'
,28,3,
CASE @emotion
WHEN 'happy' THEN '^ ^'
WHEN 'exasperated' THEN 'u u'
WHEN 'euphoric' THEN '* *'
WHEN 'shocked' THEN 'O O'
WHEN 'winking' THEN '^ -'
WHEN 'amazed' THEN '^ ^'
WHEN 'smiling' THEN 'n n'
WHEN 'apprehensive' THEN '. .'
WHEN 'sleeping' THEN '- -'
WHEN 'crying' THEN '; ;'
WHEN 'sad' THEN 'T T'
WHEN 'dizzy' THEN '@ @'
WHEN 'amazed' THEN 'O O'
WHEN 'astonished' THEN '* *'
WHEN 'pained' THEN '> <'
WHEN 'angry' THEN '¬ ¬'
WHEN 'dead' THEN 'X X'
WHEN 'bored' THEN '= ='
WHEN 'miserable' THEN '! !'
WHEN 'incredulous' THEN 'o O'
WHEN 'confused' THEN 'p q'
WHEN 'seriously?' THEN 'o o'
WHEN 'serious' THEN ''' '''
WHEN 'puzzled' THEN '? ?'
WHEN 'dispairing' THEN '/ \'
WHEN 'low' THEN 'u u'
WHEN 'depressed' THEN '?'
WHEN 'insincere' THEN '?'
WHEN 'sadder' THEN 'Y Y'
WHEN 'aquisitive' THEN '$ $'
WHEN 'mad' THEN '?'
WHEN 'amorous' THEN '♥ ♥'
WHEN 'sleepy' THEN 'z z'
ELSE '???'
END)
END
GO
--regression test suite
--Select dbo.ufsEmotionalTeddy()
SELECT dbo.ufsEmotionalTeddy('happy')
SELECT dbo.ufsEmotionalTeddy('exasperated')
SELECT dbo.ufsEmotionalTeddy('euphoric')
SELECT dbo.ufsEmotionalTeddy('shocked')
SELECT dbo.ufsEmotionalTeddy('winking')
SELECT dbo.ufsEmotionalTeddy('amazed')
SELECT dbo.ufsEmotionalTeddy('smiling')
SELECT dbo.ufsEmotionalTeddy('apprehensive')
SELECT dbo.ufsEmotionalTeddy('sleeping')
SELECT dbo.ufsEmotionalTeddy('crying')
SELECT dbo.ufsEmotionalTeddy('sad')
SELECT dbo.ufsEmotionalTeddy('dizzy')
SELECT dbo.ufsEmotionalTeddy('amazed')
SELECT dbo.ufsEmotionalTeddy('astonished')
SELECT dbo.ufsEmotionalTeddy('pained')
SELECT dbo.ufsEmotionalTeddy('angry')
SELECT dbo.ufsEmotionalTeddy('dead')
SELECT dbo.ufsEmotionalTeddy('bored' )
SELECT dbo.ufsEmotionalTeddy('miserable')
SELECT dbo.ufsEmotionalTeddy('incredulous' )
SELECT dbo.ufsEmotionalTeddy('confused')
SELECT dbo.ufsEmotionalTeddy('seriously?')
SELECT dbo.ufsEmotionalTeddy('serious' )
SELECT dbo.ufsEmotionalTeddy('puzzled' )
SELECT dbo.ufsEmotionalTeddy('dispairing')
SELECT dbo.ufsEmotionalTeddy('low' )
SELECT dbo.ufsEmotionalTeddy('depressed' )
SELECT dbo.ufsEmotionalTeddy('insincere' )
SELECT dbo.ufsEmotionalTeddy('sadder')
SELECT dbo.ufsEmotionalTeddy('aquisitive' )
SELECT dbo.ufsEmotionalTeddy('mad' )
SELECT dbo.ufsEmotionalTeddy('amorous' )
SELECT dbo.ufsEmotionalTeddy('sleepy')
January 26, 2007 9:10 AM
 

john said:

nice article
January 28, 2007 10:53 PM
 

Peter Falconer said:

If someone could suggest a suitable Mangacon (Mangaticon?) for 'stark raving loony' (or perhaps 'barking mad' as this, on the face of it, offers more immediate scope for a visual interpretation) I will be happy to comment on this article. Until then I fell somewhat hamstrung (wouldn't mind a Mangacon for that either!)
January 31, 2007 4:11 PM
 

ABD said:

This is the silliest thing I have ever seen.
February 1, 2007 12:20 AM
 

Phil Factor said:

Silliest? Well, thank you; but the praise is undeserved since, on this very site is a three-d graphical maze written in a stored procedure. I bow to the master at:-
Lionel's Blog: A Sql Game
February 1, 2007 3:15 PM
You need to sign in to comment on this blog

















<January 2007>
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910
On the Trail of the Expanding Databases
 It is sometimes difficult for other IT people to understand the constraints that DBAs have to work... Read more...

SQL Server 2008: The New Data Types
 Brad continues his helicopter-level view of the most interesting new features of SQL Server 2008 with a... Read more...

Reporting on Mobile Device Activity Using Exchange 2007 ActiveSync Logs
 In this new column giving practical advice on all things Sys Admin related, Ben Lye takes on the often... Read more...

The Bejeweled Puzzle in SQL
 Alex Kozak provides another SQL puzzle to hone your SQL Skills with.  Read more...

Using Powershell to Generate Table-Creation Scripts
 For all of us who learn best by trying out examples, Bob Sheldon produces a PowerShell script file for... Read more...