USE XSCJ
GO
IF object_id('tempdb..#tmpTable') IS NOT NULL
DROP TABLE #tmpTable
SELECT TOP 10 *
INTO #tmpTable
FROM 学生基本信息表
WHERE 性别 = '女'
GO
DECLARE @zbs CHAR(10)
SELECT @zbs = 族别 FROM #tmpTable
WHERE 出生日期 = (SELECT MIN(出生日期) FROM #tmpTable)
IF @zbs = '汉族'
PRINT '她是汉族的'
ELSE
PRINT '她不是汉族的'
GO
GO
IF object_id('tempdb..#tmpTable') IS NOT NULL
DROP TABLE #tmpTable
SELECT TOP 10 *
INTO #tmpTable
FROM 学生基本信息表
WHERE 性别 = '女'
GO
DECLARE @zbs CHAR(10)
SELECT @zbs = 族别 FROM #tmpTable
WHERE 出生日期 = (SELECT MIN(出生日期) FROM #tmpTable)
IF @zbs = '汉族'
PRINT '她是汉族的'
ELSE
PRINT '她不是汉族的'
GO
文章来源:http://henrya2.blog.163.com/blog/static/7545141920081021102850597