求季度报表where写法
有一个存储过程,应该统计季度的金额情况,传入参数为年,与1,2,3,4这样的值型,后面代表四个季度
例如
select ... from table1 where date1 ....
date1为日期型
这里的where 怎么写比较方便
另外因为其它原因不方便用
declare @sql varchar(2000)
set @sql= "select ....from "
execute (@sql)这样的方式,有什么好办法吗
------解决方案--------------------datepart(quarter,getdate())
------解决方案--------------------declare @year as int
set @year = 2007
declare @quarter as int
set @quarter = 3
select * from tb where year(date1) = @year and datepart(quarter,date1) = @quarter
------解决方案--------------------declare @year as int
set @year = 2007
declare @quarter as int
set @quarter = 3
select sum(金额) as cast(@year as varchar) + '年第 ' + cast(@quarter) + '季度金额统计情况 ' from tb where year(date1) = @year and datepart(quarter,date1) = @quarter