本文介绍了在存储过程中需要来自不同sql查询的一个结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在执行带有多个select语句的存储过程,而不是为每个select语句生成不同的结果集,我所需要的只是从存储过程中sql查询的所有select语句中获得一个结果集.... ..HERE是SP代码..
MS SQL语法(切换纯文本)
Hi i am making a stored procedure with multiple select statements when i execute them than different resultset are maken for each select statement all i need is to get one resultset from all select statements of sql quries in the stored procedure......HERE is the SP code..
MS SQL Syntax (Toggle Plain Text)
SET NOCOUNT ON;
SELECT COUNT(*) AS totalEmployees FROM dbo.Add_Employees
SELECT DISTINCT dbo.Add_Employees.gender, COUNT(Add_Employees.employee_uniqueId) AS AccGender
FROM dbo.Add_Employees
GROUP BY(Add_Employees.gender)
SELECT DISTINCT dbo.Add_Employees.department, COUNT(Add_Employees.employee_uniqueId) AS Accdepartment
FROM dbo.Add_Employees
GROUP BY(Add_Employees.department)
SELECT DISTINCT dbo.Add_Employees.designation, COUNT(Add_Employees.employee_uniqueId) AS Accdesignation
FROM dbo.Add_Employees
GROUP BY(Add_Employees.designation)
SELECT DISTINCT dbo.Add_Employees.grade, COUNT(Add_Employees.employee_uniqueId) AS AccGrade
FROM dbo.Add_Employees
GROUP BY(Add_Employees.grade)
SELECT DISTINCT dbo.Add_Employees.country, COUNT(Add_Employees.employee_uniqueId) AS AccCountry
FROM dbo.Add_Employees
GROUP BY(Add_Employees.country)
SELECT DISTINCT dbo.Add_Employees.city, COUNT(Add_Employees.employee_uniqueId) AS AccCity
FROM dbo.Add_Employees
GROUP BY(Add_Employees.city)
END
推荐答案
UNION
或
UNION ALL
这篇关于在存储过程中需要来自不同sql查询的一个结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!