Monday, May 12, 2008

SQL Server - Data types

Gurus,

Hope you are doing good. In this post, I wanna post about SQL Server data types. This question might be asked to you in the interviews or in some of the database exams you have faced.

Since, it is an interesting query, I like to share with you...

Declare @int1 Int,
@int2 Int,
@answer Numeric(9,2)
Select @int1 =5, @int2=2
Select @answer = @int1 / @int2
Print @answer

What do you think would be answer? If you think that answer is 2.5, you are wrong. The right answer is: 2

Since, the integer/the integer will return a integer, the answer is 2.

As well as in the following query:

Declare @int1 Numeric(9,2),
@int2 Numeric(9,2),
@answer Int
Select @int1 =5.5, @int2=2.0
Select @answer = @int1 * @int2
Print @answer


Here, the answer is 12.

Gurus, enjoy coding... C U later....
Take care...
-Harikaran.S

No comments: