帮我解释一下下面的存储过程,看不太明白,特别是union的作用
CREATEPROCEDURE本月概况@Date1datetimeASSELECT'接收月小计'AS项目,Count(*)AS数量,10ASSFROMtabstateWH...
CREATE PROCEDURE 本月概况
@Date1 datetime
AS
SELECT '接收月小计' AS 项目,Count(*) AS 数量,10 AS S
FROM tabstate
WHERE year(writeindate)=year(@date1) and month(writeindate)=month(@date1) and writeflag=1
union
select '接收年累计' as 项目,count(*) as 数量,20 as s
from tabstate
where year(writeindate)=year(@date1) and writeflag=1
ORDER BY S
GO 展开
@Date1 datetime
AS
SELECT '接收月小计' AS 项目,Count(*) AS 数量,10 AS S
FROM tabstate
WHERE year(writeindate)=year(@date1) and month(writeindate)=month(@date1) and writeflag=1
union
select '接收年累计' as 项目,count(*) as 数量,20 as s
from tabstate
where year(writeindate)=year(@date1) and writeflag=1
ORDER BY S
GO 展开
展开全部
说明白了,存储过程也是就是段SQL语句,只是为了方便再用的时候再写再编译,
CREATE PROCEDURE 本月概况 // 这里是定义
@Date1 datetime //定义一个变量
AS
SELECT '接收月小计' AS 项目,Count(*) AS 数量,10 AS S
FROM tabstate
WHERE year(writeindate)=year(@date1) and month(writeindate)=month(@date1) and writeflag=1 //这是一个select 语句
union //这是一个关键字,用来合并表的。具体语法去看看SQL帮助。
select '接收年累计' as 项目,count(*) as 数量,20 as s
from tabstate
where year(writeindate)=year(@date1) and writeflag=1
ORDER BY S //这也是一个SELECT 语句。
-------------
具体建议你,有不清楚的语法去看看SQL帮助,那里写得很清楚还有例子。
CREATE PROCEDURE 本月概况 // 这里是定义
@Date1 datetime //定义一个变量
AS
SELECT '接收月小计' AS 项目,Count(*) AS 数量,10 AS S
FROM tabstate
WHERE year(writeindate)=year(@date1) and month(writeindate)=month(@date1) and writeflag=1 //这是一个select 语句
union //这是一个关键字,用来合并表的。具体语法去看看SQL帮助。
select '接收年累计' as 项目,count(*) as 数量,20 as s
from tabstate
where year(writeindate)=year(@date1) and writeflag=1
ORDER BY S //这也是一个SELECT 语句。
-------------
具体建议你,有不清楚的语法去看看SQL帮助,那里写得很清楚还有例子。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询