Skip to main content
nikos101
Inspiring
November 26, 2008
Question

I'm having some bother with variables?

  • November 26, 2008
  • 2 replies
  • 462 views
I'm having some bother with variables?

In ms sql if @AS@adobe.com @706459 is NULL then @a is always null.

@a = @AS@adobe.com + @706459

What is the best way to make sure @a contains a value if either @amountSpot or @amountForward contains a number?

set @a = @amountSpot + @amountForward
This topic has been closed for replies.

2 replies

Inspiring
November 26, 2008
> In ms sql if @aS @aF is NULL then @a is always null

Yes. Take a look MS SQL's ISNULL(..) function. You can use it to substitute a default value whenever the main value is null. Use whatever default value is appropriate in your case.

set @a = ISNULL(@amountSpot, 0) + ISNULL(@amountForward , 0)
Inspiring
November 26, 2008
nikos101 wrote:
> I'm having some bother with variables?
>
> In ms sql if @aS @aF is NULL then @a is always null.
>
> @a = @aS + @aF
>
> What is the best way to make sure @a contains a value if either @amountSpot
> or @amountForward contains a number?
>
> set @a = @amountSpot + @amountForward
>

You need one of the NULL functions, probably COALESCE(), but pick for
yourself.
http://www.w3schools.com/SQL/sql_isnull.asp
SQL NULL Functions