Sunday, April 17, 2011

SQL server order of precedence


Anyone who has been writing queries must have come across a situation where somehow the query looks fine but the result is not matching to the expectation. Well then one major problem here is that you are not aware of the logical or arithmetic operator sequence. I have tried to simplify, present to you the order that you should have in mind.



1~ (Bitwise NOT)
2* (Multiply), / (Division), % (Modulo)
3+ (Positive), - (Negative), + (Add), (+ Concatenate), - (Subtract), & (Bitwise AND), ^ (Bitwise Exclusive OR), | (Bitwise OR)
4=, >, <, >=, <=, <>, !=, !>, !< (Comparison operators)
5NOT
6AND
7ALL, ANY, BETWEEN, IN, LIKE, OR, SOME
8= (Assignment)



for everyone’s reference if any query has 2 operators with the sample level of precedence then the operator is evaluated from left 2 right as rule of thumb, to override this you can use brackets to increase precedence. 
Hold Up

Wednesday, December 22, 2010

ASP.Net Event Sequence

I have often seen developers struggle with coding due to the simple fact that they don't realize what event follows what, here is quick list of event sequence. some of the events are very rarely used and might not be so important, something like load event sequences is important and is often confused see below.

Load event Sequence
1. Content page Load event.
2. Master page Load event.   
3. Master page controls Load event.
4. Content page controls Load event.


The following is the sequence in which every events occur when a master page is merged with a content page:
  1. Content page PreInit event.
  2. Master page controls Init event.
  3. Content controls Init event.
  4. Master page Init event.
  5. Content page Init event.
  6. Content page Load event.
  7. Master page Load event.
  8. Master page controls Load event.
  9. Content page controls Load event.
  10. Content page PreRender event.
  11. Master page PreRender event.
  12. Master page controls PreRender event.
  13. Content page controls PreRender event.
  14. Master page controls Unload event.
  15. Content page controls Unload event.
  16. Master page Unload event.
  17. Content page Unload event.

kick it on DotNetKicks.com

Wednesday, August 11, 2010

Novice with mobile apps

When i started with VB6 someone told me there is nothing better than application (desktop) development, web is just a fragment of what you can do with application development, then with a shift in technology i moved to web development I did some really good work but most of it was web applications and not websites. now with almost 7 years of web development experience, i feel like a novice when i comes to mobile apps and top that off  they differ based on platform OS, there is that pioneering technology call iPhone apps and then we have Android apps and of course there are those windows mobile apps, blackberry apps, and Nokia symbian apps....


my interests lie in Android and to some extent iPhone apps..... looking forward to exploring and understand the technology and frameworks....   i will update the blogs with tit-bits i learn over a period of time. 

Monday, December 14, 2009

Data Types in SQL Server 2008


I Read a great article on database journal lately about data types in 2008
, i am sharing some basic info.

Numeric data types 


An Integer is a counting number with no decimal point or fractional piece. All negative numbers, positive numbers, and zero are integers. SQL Server breaks integers into four sizes:

BigInt: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Int: -2,147,483,648 to 2,147,483,648

SmallInt: -32,768 to 32,767

TinyInt: 0 to 255


Here as a part of software design you need to clear what to use in which cases, it may be a simple choice to pick the largest range, but looking deep you need to understand first Bigint uses double the space as int, and the other being the application consuming the database gets what it expects and there are not overflow errors.

for decimal value numbers, there are  Decimal, Numeric, Money, and SmallMoney. The types Decimal and Numeric are functionally the same thing. Meaning, they will work, calculate and behave identically, the only difference is in the mathematical definition and not in the way SQL Server utilizes them.

Money and SmallMoney are really Decimals with a fixed amount of four decimal places to the right. SmallMoney can be valued from - 214,748.3648 to 214,748.3647 while the range of Money is from -922,337,203,685,477.5808 to 922,337,203,685,477.5807. One of the reasons for using Money rather than a Decimal includes the display option of dollar signs and commas after three digits.


Strings  


Here we will discuss Char, VarChar, and Text. As most of you might me aware of difference between char and varchar, where when a char(50) and varchar(50) columns are defined, char takes up 50 Bytes in respective of size of content saved in the column where varchar is flexible and takes up bytes required to save the length of the content. 


Char must be used in case of where it is know or understood that length of the text would be fixed like a char(1) column would make much more sense in case of a Sex column where only M/F is expected to saved instead of varchar, where as something like name should be varchar. 


Varchar has a max limit of 8000, though a new introduction of Varchar(max) has made it more flexible as the size can be unlimited in this case, and the main benefit of this is that as in case of Text column string operations cannot be done, while here all the string operations can be handled easily. Also the thing to note here is that Varchar(max) is all set to replace text in the future versions of SQL server as Text is supported in 2008 only as a part of backward compatibility. 


I will adding more to this, hope you like it.... please Digg, Kick or share this if you like this.     


kick it on DotNetKicks.com