当前位置: 代码迷 >> Sql Server >> 大神帮小弟我看看题目如何解决
  详细解决方案

大神帮小弟我看看题目如何解决

热度:25   发布时间:2016-04-24 20:13:10.0
大神帮我看看题目怎么解决
大概题目就是这样子。是我昨天面试没做出来题目

@x declare varchar(10) ,@y declare varchar(10) set @y=''

1.select @x/0
2.select @x/2
3.select @y/0
4.select @y/2
以上表达式,哪些有错误

------解决方案--------------------
declare @x int , --varchar(10)是字符型不能计算
        @y  int
set @x=2 
set @y=3
--select @x/0 0不能做除数,否则会报错
select @x/2
--select @y/0 0不能做除数,否则会报错
select @y/2   

------解决方案--------------------

第3个是错误的哈



declare @x varchar(10) 
declare @y varchar(10) 
set @y=''

select @x/0   --null/0 返回null,不会报错

select @x/2

/*
消息 8134,级别 16,状态 1,第 9 行
遇到以零作除数错误。
*/
select @y/0

select @y/2
  相关解决方案