select a.tmp1,isnull(b.name,'不详') from a left join b
on a.id = b.id
解决方案 »
- sql用户数据统计
- SQL 语句?
- 查询问题
- 有关 RollUp 的问题 ,请大师们指教!!!!
- 对两个字段求和:select sum(field1) + sum(field2),如果field1的值为NULL,则结果也为NULL,
- 还是关于新闻发布系统分类查询的问题
- 急的很,我的数据库为什么不能登录??
- 怎样通过VB调用SQL SERVER 中设好的LOCAL PACKAGES?
- 跪求外接表的列生成交叉表的存储过程,急!
- 求救啊~~~~~~~~~~~~~~~有问题,谢谢高手帮忙
- 要建一网站,大家帮忙分析一下数据库如何设计?
- 请指教:关于sql分组后选符合某条件的某主键列的问题,高手都来看看!
>------------------------------------------
语法
ISNULL ( check_expression , replacement_value ) 参数
check_expression将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。replacement_value在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。 返回类型
返回与 check_expression 相同的类型。注释
如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。
on a.id = b.id如果类型不合适,还要转换一下类型
select a.tmp1,b.name from a left join b
on a.id = b.id)cselect tmp1,name=case when null then '不祥' else name end from #t
select * into #t from(
select a.tmp1,b.name from a left join b
on a.id = b.id)cselect tmp1,name=case name when null then '不祥' else name end from #t
declare @a table(tmp1 char(1),[name] char(4))
insert into @a
select 'A', '上海' union all
select 'B', '北京' union all
select 'C', NULL union all
select 'D', '天津'--查询
select tmp1,[name]=coalesce(name,'不祥') from @a--结果
/*
tmp1 name
---- ----
A 上海
B 北京
C 不祥
D 天津
*/
on a.id = b.id