declare @j int
declare @SIID varchar(64)
create table #tblXu1
(
iid varchar(64),
sname varchar(20),
Dname varchar(20),
jcf decimal(10,2),
)
set @j=(select count(*) from STAFF )
set @i=1
while @i<=@j
begin
set @SIID= (select SIID from ( select ROW_NUMBER() over (order by s.IID asc ) as Row,
s.IID SIID from STAFF s left join DEPARTMENT d on s.DEPARTMENTIID=d.IID where s.ISREGISTERED=1 and D.ISREGISTERED=1) as sp where Row=@i)
insert into #tblXu1
select IID,s.NAME SNAME, D.NAME DNAME.....
set @i=@i+1
end
select * from #tblXu1
drop table #tblXu1
6 个解决方案
#1
按照你的思路试了一下,未发现你说的问题.
create table #tb(id int)
go
declare @i as int
set @i = 1
while @i <= 10
begin
insert into #tb values(@i)
set @i = @i + 1
end
select * from #tb
drop table #tb
/*
id
-----------
1
2
3
4
5
6
7
8
9
10
(所影响的行数为 10 行)
*/
#2
晕 太奇怪了
#3
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[#tab1]'))
drop table [dbo].[#tab1]
GO
drop table [dbo].[#tab1]
GO
#4
你可以尝试把while里面的内容弄简单点,看看行不行?
#5
临时表的作用域问题?
#6
解决了 谢谢各位了 原来是创建临时表时 下面没写 那个关键字 GO 唉!
#1
按照你的思路试了一下,未发现你说的问题.
create table #tb(id int)
go
declare @i as int
set @i = 1
while @i <= 10
begin
insert into #tb values(@i)
set @i = @i + 1
end
select * from #tb
drop table #tb
/*
id
-----------
1
2
3
4
5
6
7
8
9
10
(所影响的行数为 10 行)
*/
#2
晕 太奇怪了
#3
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[#tab1]'))
drop table [dbo].[#tab1]
GO
drop table [dbo].[#tab1]
GO
#4
你可以尝试把while里面的内容弄简单点,看看行不行?
#5
临时表的作用域问题?
#6
解决了 谢谢各位了 原来是创建临时表时 下面没写 那个关键字 GO 唉!