34,587
社区成员
发帖
与我相关
我的任务
分享
select distinct [name]
from @tb
where name <> ''
declare @Tb table (name varchar(10))
insert into @tb
select '张三'
union all select null
union all select '张三'
union all select '李四'
union all select ''
union all select '张三'
union all select '李四'
select distinct [name]
from @tb
where isnull(name,'')<>''
/*
name
----------
李四
张三
(所影响的行数为 2 行)
*/
declare @Tb table (name varchar(10))
insert into @tb
select 'aaa'
union all select null
union all select 'aaa'
union all select 'bb'
union all select null
union all select 'aaa'
union all select 'ccc'
--以下为对比
select distinct [name]
from @tb
/*
name
----------
NULL
aaa
bb
ccc
(所影响的行数为 4 行)
*/
select distinct [name]
from @tb
where name is not null
/*
name
----------
aaa
bb
ccc
(所影响的行数为 3 行)
*/
declare @Tb table (name varchar(10))
insert into @tb
select 'aaa'
union all select null
union all select 'aaa'
union all select 'bb'
union all select null
union all select 'aaa'
union all select 'ccc'
select distinct [name]
from @tb
where name is not null
select distinct [name] from tb where [name] is not null
select name from tb where name is not null group by name
select name from tb group by name
Select distinct Name