开发者

Subtracting NULL from a decimal (SQL Server)?

I have this query here:

@someDecimal - (select sum(amount) from SomeTable)

I have similiar queries using select sum(amount) from SomeTable to calculate some values. Thing is, if there are no values in SomeTable, the result is NULL. Now I can use ISNULL each time I am using select sum(开发者_开发百科amount) from SomeTable to calculate something, but its the same thing over and over again. I was wondering if there is some way to calculate that once, set it to 0 if its NULL and use that instead. I am having this caculation in a WITH region.

;WITH MyWithStuff AS (.....)

I am using SQL Server 2008.

Thanks :-)


this behavior is called ANSI NULLS and it can be enabled or disabled per connection, using the SET ANSI_NULLS OFF (or ON). heres the link to SQL BOL, note that MS sais there that in the future turning it off will not be supported, so ISNULL or COALESCE is the way to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜