0

私の状況は、私のウェブサイトにログインした後、アクティブな従業員、非アクティブな従業員、および部門ごと、コラージュごとの従業員数のリストを表示したかったことです。

そのために、存在しない場合は一時テーブルを作成する手順を作成し、それ以外の場合はテーブルを削除して一時テーブルを作成し、その後、従業員数、条件付きの部門を取得するための 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.
4

1 に答える 1