[英]Sql server temp table
I need to create a temp table who contains the number of employes of each department.我需要创建一个包含每个部门员工人数的临时表。 If the department have no employer, we need to print a message.如果部门没有雇主,我们需要打印一条消息。
IF (count(*) = 0)
BEGIN
PRINT 'Espace vide'
END
else
Select deptno,count(*)
from emp
group by deptno;
this is the query to see how many employes are in each dept, but I don't know how to create a temp table with it.这是查看每个部门有多少员工的查询,但我不知道如何用它创建临时表。
Choose suitable for you method:选择适合您的方法:
Select deptno,count(*) cnt
INTO #TempTable
from emp
group by deptno;
select
*,
CASE cnt WHEN 0 THEN 'Espace vide' ELSE NULL END AS column1
FROM #TempTable
if exists(SELECT * FROM #TempTable WHERE cnt = 0) PRINT 'Espace vide'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.