select '1' ID into #tempselect isnull(B.统计数,0) 统计结果 from #temp AA left join (select ID,isnull(count(ID),0) 统计数 from dbo.Action group by ID) B on AA.ID=B.ID drop table #temp
select isnull(count(*),0) from table -------------------------- 不行 什么都没显示 我之前就是用的这个 select '1 ' ID into #temp -------------------------- 不行 我不能修改别人的数据库
declare @a int select @a=count(*) from XX where XXif @a=null @a=0 go
declare @a int select @a=count(*) from XX where XXif @a=null @a=0 go
似乎用 Select Count(*) From 表 where 条件 当条件不满足时,返回结果就是0,没有必要用isNULL来转换!!楼主还是把自己的问题描述清楚些
declare @t table(id int) insert @t select 1select isnull(count(*),0) as [count] from @tdelete from @tselect isnull(count(*),0) as [count] from @t/*(所影响的行数为 1 行)count ----------- 1(所影响的行数为 1 行) (所影响的行数为 1 行)count ----------- 0(所影响的行数为 1 行) */
if not exists(select top 1 * from table where 条件) select [count] = 0 else select [count] = count(*)from table 条件
当条件不满足时,返回结果就是0,没有必要用isNULL来转换 比如下面语句就是返回0use northwind select count(*) from dbo.Customers where customerid='csdn'use northwind select count(*) from dbo.Customers where customerid='csdn'
into #tempselect isnull(B.统计数,0) 统计结果 from #temp AA left join
(select ID,isnull(count(ID),0) 统计数 from dbo.Action group by ID) B
on AA.ID=B.ID
drop table #temp
--------------------------
不行 什么都没显示 我之前就是用的这个
select '1 ' ID
into #temp
--------------------------
不行 我不能修改别人的数据库
select @a=count(*)
from XX
where XXif @a=null
@a=0
go
select @a=count(*)
from XX
where XXif @a=null
@a=0
go
Select Count(*) From 表 where 条件
当条件不满足时,返回结果就是0,没有必要用isNULL来转换!!楼主还是把自己的问题描述清楚些
insert @t select 1select isnull(count(*),0) as [count] from @tdelete from @tselect isnull(count(*),0) as [count] from @t/*(所影响的行数为 1 行)count
-----------
1(所影响的行数为 1 行)
(所影响的行数为 1 行)count
-----------
0(所影响的行数为 1 行)
*/
select [count] = 0
else
select [count] = count(*)from table 条件
比如下面语句就是返回0use northwind
select count(*) from dbo.Customers
where customerid='csdn'use northwind
select count(*) from dbo.Customers
where customerid='csdn'