declare @n int select @n=isnull(count(*)-1, 0) from tab where somefield=somevalue exec('select top '+@n+' * from tab where somefield=somevalue ')
TO:marco08(天道酬勤) 出现了“1行被上次查询影响”结果集什么都没有
select * from tab where somefield=somevalue --有多少行數據
select * from tab where somefield=somevalue --如果只有一行, 按你的要求最后一行不要, 那麽就不會返回結果集
企业管理器里面测试加WHERE條件了嗎?
declare @i int select @i=count(1) from table where condition=con if @i>0 then select top @i * from table where condition=con
--trydeclare @n int select @n=count(*) from tab where somefield=somevalue if @n>1 set @n=@n-1set rowcount @n select * from tab where somefield=somevalue set rowcount 0
最后一个是最新的吗?select * from tab where id <> (select top 1 t1.id from tab t1 order by t1.datetime desc)
declare @n int select @n=count(*) from tab where somefield=somevalue if @n>1 set @n=@n-1set rowcount @n select * from tab where somefield=somevalue set rowcount 0---这个应该没问题的,楼主在哪儿看到一行被影响?
set nocount on declare @n int select @n=count(*) from tab where somefield=somevalue if @n>1 set @n=@n-1set rowcount @n select * from tab where somefield=somevalue set rowcount 0 SET NOCOUNT OFF
select @n=isnull(count(*)-1, 0) from tab where somefield=somevalue
exec('select top '+@n+' * from tab where somefield=somevalue ')
出现了“1行被上次查询影响”结果集什么都没有
select @i=count(1) from table where condition=con
if @i>0 then
select top @i * from table where condition=con
select @n=count(*) from tab where somefield=somevalue
if @n>1
set @n=@n-1set rowcount @n
select * from tab where somefield=somevalue
set rowcount 0
在关键字“THEN”附近语法错误不加THEN:
在第一行@i处语法错误
select @n=count(*) from tab where somefield=somevalue
if @n>1
set @n=@n-1set rowcount @n
select * from tab where somefield=somevalue
set rowcount 0---这个应该没问题的,楼主在哪儿看到一行被影响?
declare @n int
select @n=count(*) from tab where somefield=somevalue
if @n>1
set @n=@n-1set rowcount @n
select * from tab where somefield=somevalue
set rowcount 0
SET NOCOUNT OFF