首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

哪位高手能解释一下,为什么select结果不同

2012-04-04 
谁能解释一下,为什么select结果不同?SQL codeif object_id(tb) is not null drop table tbgocreate tabl

谁能解释一下,为什么select结果不同?

SQL code
if object_id('tb') is not null drop table tbgocreate table tb(col nvarchar(max))goinsert into tb select 'abc' union allselect 'def'goselect right('abc',0)   --显示为空select right('def',0)   --显示为空select col,right(col,0) from tb  --显示为Null

这个是为什么呢?

[解决办法]
SQL code
if object_id('tb') is not null drop table tbgocreate table tb(col nvarchar(max))goinsert into tb select 'abc' union allselect 'def'goselect right('abc',0)--显示为空(无列名)select right('def',0)   --显示为空(无列名)select col,right(col,0) from tb /*col    (无列名)abc    def    */我这全为空,没出现null
[解决办法]
楼主是什么环境,以下测试环境是没问题的,结果一致
环境:
SQL code
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (X64)   Jul  9 2008 14:17:44   Copyright (c) 1988-2008 Microsoft Corporation  Enterprise Evaluation Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: ) (VM)
[解决办法]
SQL code
declare @a varchar(10)set @a=N'abc'select right(@a,0)select right(convert(nvarchar(max),'def'),0----(1 row(s) affected)----------------------------------------------------------------------------------------------------------------NULL(1 row(s) affected) 

热点排行