SET behaviour by assigning DEFAULT values for variables

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 386
For example, the default value of INT is NULL. Make sure that the INT variable have to initialized before using it further in calculations

What is the result of below query ?

DECLARE @Var INT
select @Var+GETDATE()+14.67 as TimeCalculationWithInt


Output is NULL. Its because of the initial value of INT variable.

By assinging deafult value while declaration itself, we can avoid/prevent simple logical issues
DECLARE @Var INT = 0 
select @Var+getdate()+14.67 as TimeCalculation
GO


Result is

TimeCalculation
2015-04-15 07:02:27.920

Comments or Responses

Login to post response