isnull(Sdept,'IS')的意思是判断Sdept是否为空,若为空则用'IS'代替。
可和后面的='IS'边起来,哪位说说:
isnull(Sdept,'IS')= 'IS ';
是什么意思?
可和后面的='IS'边起来,哪位说说:
isnull(Sdept,'IS')= 'IS ';
是什么意思?
解决方案 »
- 求教sql中的GetDate函数格式问题,如何精确到分钟,
- 请问日志文件包含“页”吗?
- mysql 几个表数据合并在一起 出现主键id 重复 怎么办
- 求借助另一个表进行 行转列的sql语句
- sql server 2008 不能用windos登陆 也不能用sa登陆
- 求sql
- 菜鸟问题!怎么建立一个数据库啊?我想连接到自己的机子上!
- 请教,请问调用函数时,函数中能否执行存储过程
- 各位大虾,快到这里来,有一个很难的问题
- 对Sql server的一点意见
- 关于字符串的数字相加的问题
- 请教:INSERT 语句与 COLUMN FOREIGN KEY 约束 'FK_FlowStepPerson_FlowStep' 冲突。
======如果Sdept为null(不是为空),则取值为‘IS’,否则为Sdept.isnull(Sdept,'IS')= 'IS ';
===============
可以理解为一个条件,由具体业务逻辑决定。
先判断Sdept='IS',若Sdept为null,则让Sdept='IS'
视图创建语句为:
create view [dbo].[IS_Student]
as
select Sno,Sname,Sage
from Student
where isnull(Sdept,'IS')= 'IS ';
isnull(Sdept,'IS')= 'IS ';
=================
只是逻辑中的一部分,它的上下文呢?
举个例子,不过不太合理:
if isnull(Sdept,'IS')= 'IS '
---update tb
else
---insert into tb
====
等价于:
create view [dbo].[IS_Student]
as
select Sno,Sname,Sage
from Student
where Sdept is null;
这个意思就是说查询出student表中的所有的sdept的值为IS或者为null的所有记录,当为null时就用IS代替,IS当然等于IS了,如果本身的值就为IS,那么也可以查询出来。
go
if object_id('test.dbo.tb') is not null drop table tb
-- 创建数据表
create table tb
(
dept char(3),
id int
)
go
--插入测试数据
insert into tb select 'IS',101
union all select null,107
union all select 'MA',113
union all select 'IS',118
union all select 'CS',124
go
--代码实现select * from tb/*测试结果dept id
---------------
IS 101
NULL 107
MA 113
IS 118
CS 124(5 行受影响)
*/select * from tb where isnull(dept,'IS')='IS'/*测试结果dept id
---------------
IS 101
NULL 107
IS 118(3 行受影响)
*/select * from tb where dept='IS' or dept is null/*测试结果dept id
---------------
IS 101
NULL 107
IS 118(3 行受影响)
*/
http://topic.csdn.net/u/20071114/21/a16793d7-7f32-4aee-b374-0bf44444b733.html?86882
isnull(sdept,'is') = is==> 不就是:sdept is null or sdept = 'is'
然后再判断 Sdept 的值是否等于‘IS’
这是个布尔表达式,而且是出现在where子句如果表达式右侧的常量真的含有一个空格,
那么这个表达式逻辑上等效于找出Sdept等于'IS '值的记录,
这时候,null不会被检出,因为null被转换成'IS'了,'IS'不等于'IS '如果那个空格是笔误造成的,表达式事实上是:isnull(Sdept,'IS')= 'IS',
逻辑上等效于找出Sdept为null值 或者 Sdept等于'IS'值的记录
============
Sdept = 'IS' or Sdept is null
我真烦透了,你们不仔细看题和别人的回复吗?
都已经说了,视而不见!
'IS'= 'IS '?????
注意那个空格!!!
可和后面的='IS'边起来,哪位说说:
isnull(Sdept,'IS')= 'IS ';
是什么意思?
先判断是否为空,若为空则用'IS'代替,否则为Sdept
再与'IS'比较是否相等在sql server 2000 中 'IS'与'IS '是相等
等价于:
(Sdept='IS' or Sdept is null)
(sdept=@sdept or ISNULL(@sdept ,'')='')
意思是:如果@sdept有传值进来,就过滤,否则不过滤。
begin
end
不等价。
等价于Sdept='IS' Or Sdept Is Null