---------------------------------------------------------------- -- Author :fredrickhu(我是小F,向高手学习) -- Date :2009-12-02 14:18:38 -- Version: -- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) -- Nov 24 2008 13:01:59 -- Copyright (c) 1988-2005 Microsoft Corporation -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1) -- ---------------------------------------------------------------- --> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([A] int,[B] int) insert [tb] select 1,null union all select null,3 union all select 2,4 --------------开始查询-------------------------- select *,c=isnull(a,0)+isnull(b,0) from tb ----------------结果---------------------------- /* A B c ----------- ----------- ----------- 1 NULL 1 NULL 3 3 2 4 6(3 行受影响) */
[code=SQL]create table [tb]([A] int,[B] int) insert [tb] select 1,null union all select null,3 union all select 2,4select a , b , c = isnull(a , 0) + isnull(b,0) from tbdrop table tb/* a b c ----------- ----------- ----------- 1 NULL 1 NULL 3 3 2 4 6(所影响的行数为 3 行) */[/code
*,c=isnull(a,0)+isnull(b,0)
from
tb
from tb
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2009-12-02 14:18:38
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([A] int,[B] int)
insert [tb]
select 1,null union all
select null,3 union all
select 2,4
--------------开始查询--------------------------
select
*,c=isnull(a,0)+isnull(b,0)
from
tb
----------------结果----------------------------
/* A B c
----------- ----------- -----------
1 NULL 1
NULL 3 3
2 4 6(3 行受影响)
*/
insert [tb]
select 1,null union all
select null,3 union all
select 2,4select a , b , c = isnull(a , 0) + isnull(b,0) from tbdrop table tb/*
a b c
----------- ----------- -----------
1 NULL 1
NULL 3 3
2 4 6(所影响的行数为 3 行)
*/[/code