我想在SQL Server的不同年份的四分之二之间找到记录。查找SQL Server中两个Quarters之间的记录?
SELECT ('Q'+cast(DATEPART(QUARTER,calldate) as varchar(3))+'-'+cast(YEAR(calldate) as varchar(4)))
period,providerid,volume as volume,type
FROM table V
where DATEPART(QUARTER,calldate) between @Q1 and @Q2 and
datepart(year,calldate) in (@Y1,@Y2) and [email protected]
这里Q1 = 4,Q2 = 3和@ Y1 = 2014 @ Y2 = 2016
Now,I have only records from Q2-2016, So it should return available records
but I am getting blank rows.
if I change the parameter like this
Here Q1=3 and Q2=4 and @Y1=2014,@Y2=2016 then i am getting records.
我想这两个季度一样(Q3-2014和Q2-2016之间的所有记录)?
年份和季度的东西是类型tinyint –
@Ramdeoangh。 。 。你有一个问题,如果他们是'tinyint',因为它不足以存储一年(https://technet.microsoft.com/en-us/library/ms187745(v=sql.105).aspx)。 –
是你全年的@年,例如2016年,但不仅仅是16年? – Cato