Tuesday, September 21, 2010

How to search for blank cells in SQL

Suppose there are some blank cells  in column [text] of the [table]. How can you find them in SQL2005?
Let's see what are not working.
  • SELECT * FROM [table] WHERE [text] IS NULL
  • SELECT * FROM [table] WHERE [text] = ''
  • SELECT * FROM [table] WHERE LEN([text]) = 0
So what is working.
  • SELECT * FROM [table] WHERE LEN([text]) = 1
This essentially implies that LEN() counts the string null terminator as one character. What a broken definition of string length!

Monday, September 13, 2010

Bloglines is going

Checking out Bloglines every other minute was a major passtime during school. Today, I suddenly found out that the website is going to shut down next month. Another example of nothing last forever (on the internet).

It is very difficult to cultivate user loyalty for a small website. And it is even more difficult to keep up with the trend for a small website. Whatever reason it is, Bloglines will be gone from my life. And I have to migrate my feeds to google reader.

Thursday, September 9, 2010

数学严重退化了

我一时间居然没法完全理解这个证明。 这完全是个退化标志。
Imagine you are stranded on a desert island (without logarithm tables or computers) and--- probably due to an emotional shock---your only concern is to find out which one among numbers πeand eπ is bigger. The solution is: take h(x)=ln(x)/x, take the derivative twice to prove that x=e is a maximum, and that gives eπ is bigger.

Wednesday, September 8, 2010

Thoughts on AU government

Finally, there is an Australian government ("Like I care..."). Gillard becomes the first elected female PM. Labor didn't win the election, but win the peace.
Here are a few thoughts I have during the long-waiting 17 days of "anarchy".
  • Neither Gillard nor Abbott is liked by the majority. But Rudd is definitely disliked by the majority. So there should rather be an election be "non-PM vote", which there is no tie can occur.
  • When there is a tie, why not ask Queen?
  • If Rudd is the PM candidate for Labor, there would not be any problem for Labor to lose the election. Likewise, if Abbott is not the PM candidate for Coalition, there would not be any problem for the Coalition for Coalition to win the election. But the worst scenario just happened. 
  • Australian is still waiting for Obama to visit the land (since last year). If the independent MPs can solve it, that will be great.

Tuesday, September 7, 2010

Monty Hall problem


Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
(additional assumptions that the car is initially equally likely to be behind each door and that the host must open a door showing a goat, must randomly choose which door to open if both hide goats, and must make the offer to switch.)
Simple Solution: "Switch" yields 2/3 probability of getting a car!

Door 1Door 2Door 3result if switchingresult if staying
CarGoatGoatGoatCar
GoatCarGoatCarGoat
GoatGoatCarCarGoat

Scrum

Scrum is an iterative, incremental framework for project management and agile software development. It becomes very popular recently. MS released a process template for VS 2010. It requires a team foundation server as the platform.The tool itself is pretty cool.
http://visualstudiogallery.msdn.microsoft.com/en-us/59ac03e3-df99-4776-be39-1917cbfc5d8e

Monday, September 6, 2010

Formatting SQL output string

Step 1: Putting a record into a sentence.
You can build a sentence off a row using SELECT. For example,

SELECT [Who] + ' is going to do ' + [Item] + 'on '+ CONVERT(VARCHAR, [due], 105) + '.'
        FROM [Actions]

Step 2: Format the sentence.
When you want to putting line break or even a tab in your output, you may need CHAR function in SQL.
Tabchar(9)
Line feedchar(10)
Carriage returnchar(13)

Details see http://msdn.microsoft.com/en-us/library/ms187323.aspx

Step 3: Form an essay with multiple records.
You may need to use CURSOR to iterate the rows from the result table.