0
我的情况是在登录我的网站后,我想显示有多少员工活跃,&也是部门智慧的,拼贴智慧的员工列表。根据SQL Server 2008中的多个select语句创建表并插入行
为此,我创建了一个过程来创建临时表,如果它不存在其他drop table创建临时表,之后我写了一些SQL查询来获得雇员人数,部门条件&然后我插入记录到表。
然后我需要插入的行。现在我的问题是执行SQL中的过程执行它,但它不创建插入任何行的&,我不知道为什么会发生这种情况。如果有人知道这个问题的解决方案,请帮助我。
我的代码:
alter proc SP_TEMPRECORDFORCOUNT
as
begin
IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'TEMPRECORDFORCOUNT'))
BEGIN
drop table dbo.TEMPRECORDFORCOUNT
END
create table dbo.TEMPRECORDFORCOUNT(totalemployeecount int,activeemployeecount int,inactiveemployeecount int,deptwiseemployeecount int,activeemployeecount int)
declare @totalemployeecount int
declare @activeemployeecount int
declare @inactiveemployeecount int
declare @deptwiseemployeecount int
declare @activeemployeecount int
select @totalemployeecount =COUNT(*) from Employee
select @activeemployeecount =COUNT(*) from Employee where status=1
select @inactiveemployeecount =COUNT(*) from Employee where status=0
select @deptwiseemployeecount = count(*) from Department where e_id !=null
select @activeemployeecount = count(*) from Department d inner join Employee e on d.e_id =e.e_id where status_id=1
insert into TEMPRECORDFORCOUNT
(
totalemployeecount
,activeemployeecount
,inactiveemployeecount
,deptwiseemployeecount
,activeemployeecount
)
values
(
@totalemployeecount ,
@activeemployeecount ,
@inactiveemployeecount ,
@deptwiseemployeecount ,
@activeemployeecount ,
)
end
is it correct way thing i'm doing? if not please correct me.
谢谢它的工作很大 – 2012-04-06 07:02:41