- 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)