如: USE AdventureWorks; GO SELECT ProductNumber, Category = CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN 'Mountain' WHEN 'T' THEN 'Touring' WHEN 'S' THEN 'Other sale items' ELSE 'Not for sale' END, Name FROM Production.Product ORDER BY ProductNumber; GO
也可以用 isnull(col,'没有内容')
case when col='' then '没有内容' else col end
select case when len(ltrim(rtrim(col)))=0 then '没有内容' else col end as col from tb
select isnull(nullif([Field],''),'没有内容') from [Table]
select case when ritim(字段) is null then '没有内容' else 字段 from tb
SELECT ISNULL(字段,'没有内容') FROM TABLE
select case when colname='' then '没有内容' else colname end from tb
--> (让你望见影子的墙)生成测试数据,时间:2009-04-03
if not object_id('tb') is null drop table tb Go Create table tb([id] int,[name] nvarchar(5),[password] nvarchar(5)) Insert tb select 1,N'wang',N'wang' union all select 2,N'zhang',N'zhang' union all select 3,null,null Go Select * from tbselect id,name=case when ltrim(name) is null then '没有内容' else name end from tb
USE AdventureWorks;
GO
SELECT ProductNumber, Category =
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END,
Name
FROM Production.Product
ORDER BY ProductNumber;
GO
case when len(ltrim(rtrim(col)))=0 then '没有内容' else col end as col
from tb
from tb
SELECT ISNULL(字段,'没有内容') FROM TABLE
if not object_id('tb') is null
drop table tb
Go
Create table tb([id] int,[name] nvarchar(5),[password] nvarchar(5))
Insert tb
select 1,N'wang',N'wang' union all
select 2,N'zhang',N'zhang' union all
select 3,null,null
Go
Select * from tbselect id,name=case when ltrim(name) is null then '没有内容' else name end
from tb