USE XSCJ
GO
CREATE PROCEDURE dbo.proc_bgnum @xbh VARCHAR(8) AS
DECLARE @nBoys INT
DECLARE @nGirls INT
IF object_id('tempdb..#tmpNewTable') IS NOT NULL
DROP TABLE #tmpNewTable
SELECT 学号, 性别 INTO #tmpNewTable FROM 学生基本信息表 a, 班级表 b
WHERE a.班级编号 = b.班级编号 AND 系部编号 = @xbh
SELECT @nBoys = COUNT(*) FROM #tmpNewTable
WHERE 性别 = '男'
SELECT @nGirls = COUNT(*) FROM #tmpNewTable
WHERE 性别 = '女'
SELECT @nBoys 男生人数, @nGirls 女生人数
GO
EXEC proc_bgnum '01'
GO
CREATE PROCEDURE dbo.proc_bgnum @xbh VARCHAR(8) AS
DECLARE @nBoys INT
DECLARE @nGirls INT
IF object_id('tempdb..#tmpNewTable') IS NOT NULL
DROP TABLE #tmpNewTable
SELECT 学号, 性别 INTO #tmpNewTable FROM 学生基本信息表 a, 班级表 b
WHERE a.班级编号 = b.班级编号 AND 系部编号 = @xbh
SELECT @nBoys = COUNT(*) FROM #tmpNewTable
WHERE 性别 = '男'
SELECT @nGirls = COUNT(*) FROM #tmpNewTable
WHERE 性别 = '女'
SELECT @nBoys 男生人数, @nGirls 女生人数
GO
EXEC proc_bgnum '01'
文章来源:http://henrya2.blog.163.com/blog/static/754514192008102891428803