Posts RSS Comments RSS 129 Posts and 246 Comments till now

Archive for January, 2006

MySQL Collation for UNION

Let say you want to create a on-the-fly table which fetch the list of users with certain properties. The problem with the users is that, some of them is without any properties. Instead of displaying blank, you want to display ‘—-’. Since you want to do this on the fly, not by modifying the table. These infos will come handy.

Simply using UNION will help you to achieve above problem. Meta-SQL :

 

Select User,Properties From Users where Properties <> Null Union Select User, ‘—-’ as Properties from users where User is not in (Select User from Users where Properties <> Null)

In IIS, this will throw you Collation error if you Users table is encoded in UTF8, the Properties value of ‘—-’ will be encoded in Latin. Thus, it will throws you collation error.

In order to convert the ‘—-’ encoded as UTF8, you must use _utf8 as prefix of your string. Eq: _utf8′—-’ instead of only ‘—-’

Lesson of the day

Communicating with higher management always require tactics and tricks. Today, after making my own mistake, my manager-Ms. Judy reminded me a very good principle. Which is ..

‘Less is more’

Reporting to higher management doesn’t require us to explain all the details, we must be able to tailor the content of our report so it won’t go too much into details. Always only provide summary of the information unless they explicitely require you to go into details.

Another positive thing for giving less information is that you will cover yourself from unnecessary questioning. Sometime the details are too distracting, our boss will forget the general picture of the problem. Thus, he/she will only comments about the details without ever address the main issue.

But this doesn’t mean we dont prepare the details, we do prepare them, but only will shown them if its required.

Thanks Ms. Judy Koh =)

MS SQL version of MySQL’s Group_Concat

Today i’m doing some programming to help Budi catering JSML’s requests. At one point, i need to have an aggregate function for varchar data type. I immediately remember ‘GROUP_CONCAT’, but hey … thats MySQL. Looking through the MS SQL Book Online, couldn’t find any reference about it.

Googling for 5 minutes, i found what i want …

These are the snippets:

create table table1([id] int identity,
names varchar (50),
groupname varchar (50))

insert into table1(Names, GroupName)

select 'name1', 'group1'union
select 'name2', 'group2'union
select 'name3', 'group1'

create function concatname(@GroupName varchar(50))
Returns varchar(250)
as
BEGIN
Declare @String varchar(250)

Select @String = Coalesce(@String,'') + Names + ','
from table1
where groupName = @GroupName

set @String = left(@String, len(@String) -1)
Return @String
END

After trial and error for a couple times, i come up with my
own solution to the problem:

create function SCROverallStatus(@thelog_uid int)
returns varchar(50)
as
begin
 if (select count(*) from LMB_SML_PROC_SCR_APPROVAL where approval_level=1 and status='Approved' and log_uid=@thelog_uid)>=2
 begin
  return 'Approved'
 end

 if (select count(*) from LMB_SML_PROC_SCR_APPROVAL where approval_level=1 and status='Rejected' and log_uid=@thelog_uid)>=1
 begin
  return 'Rejected'
 end

 return 'Pending'
end

Save My Soul - Padi

Hmm.. with cloud number 9 is covering my mind .. this song makes me a little calmer ….

Save My Soul (C) Padi

Now I’m sitting here in the corner of my room
Staring through the window watching the sun goes down
And the shadows starts to creep across the floor
In this loneliness I’m crying in my bed

And the rain begins to fall down on me
As the sadness grows deep in inside of me
And I feel a little insecure right now
I am crawling looking for a place to hide

So where have all my lights gone?
For I need to find a way out of here
In my every breath I am chanting your name
Give me strength so I can save my soul…

My mind keeps telling me to hold on
And it says I have to be a real man
I’m still wondering if I’ll ever find my way
That leads me to your light, into your grace

So where have all my lights gone?
For I need to find a way out of here
In my every breath I am chanting your name
With my every breath I’m hoping
I can find the way to save my soul….


PS: Sometimes i let myself drowned in a melancholic situation … LOL … what a baby … hehe … well I always think that expressing your emotion is much better than let them entrapped inside. It is like you want to puke but you hold up because you don’t want to make a mess. Well dude, occasional puke should be bearable by other people. Just do not do it too often. :-)

A rare Google Error

As we all admitted and doctrined, Google is a 800-lbs Gorilla. The mistery of the number of PCs in their Beowulf clusters is still amazes and intrigues our curiosity.

Enough for the ass-licking Google, today i was looking for one particular email in my Gmail account. After putting the search word at the search bar, i clicked the search button .. lo … and behold …

See.. after all, our 800-lbs Gorilla sometimes want to act like the cute and chubby Orang utan …. ^_^!

Pages (2): [1] 2 »

Close
E-mail It
Socialized through Gregarious 42