Posts

Showing posts with the label programming

Custom order for SQL Query results using Order By

One thing that I surely believe is "Necessities drive Innovation". But, one has to think different at crucial times to be innovative. Well, that's not a subject of discussion for this. But it does originate from that idea. Just before our monthly release and when everything is all prepared, we found a bug in the code. GOD, how many times we test, where do they make their way. Anyways, we needed something which required no code changes as the code is already delivered. We only had database with us to play. Basically our problem was, we needed the first record from the set of two records based on a values in VARCHAR field. That means, we needed to apply some ordering to the records based on the values. But, ORDER BY only supports Alphabetic ordering on the values. But, that's what we generally know. Because we wanted to order the records in the manner we specify, we had to look for some solution. And we did find an interesting stuff at Jmatrix.net that allows us to s...

Javascript - parseInt bug

Working in javascript on the my project, I found an interesting thing which I would like to share with you all. parseInt() method in javascript is used to parse a string text into integer. For example to convert String “8” as integer 8 for processing, you will use it as follows: var parsedValue = parseInt(“8”); You can find more details about the parseInt() method on W3C Schools. http://www.w3schools.com/jsref/jsref_parseInt.asp However, there is an interesting bug with parseInt(). When you try to parseInt("08") or parseInt("09"), it returns 0. This is because the leading zero tells the parseInt() method that it is an octal number and 08 is not a valid octal value. Hence the parsing returns 0 as output. So, you might get this scenario when you trying to parse date values or month values containing leading zeros. Workaround: - Use the alternate form of parseInt(value, radix). This form forces the parsing of the string value as per your radix value. 10 indicate for de...