本文介绍了如何计算一个学期中不包括周末的总天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Declare 
 @counter int = 0,
 @strt date,
 @end date
Begin 
set @strt=(Select Distinct StartDate
		   From SchoolTerms
		   where EmisCode =''500226884'' 
		   AND CurrentYear=''2009''
		   AND Quater=''Term1'')
Set @end=(Select Distinct EndDate
		   From SchoolTerms
		   where EmisCode =''500226884'' 
		   AND CurrentYear=''2009''
		   AND Quater=''Term1'')
while (@strt<@end)
if DATEPART(weekday,@strt)<>7 or DATEPART(weekday,@strt)<> 1 
	set @counter+=1
	set @strt=@strt-1
print @strt
print @end
print @counter
End;



我有以下代码可计算一个学期的总天数,但出现以下错误.



i''ve got the following code for calculating total number of days in a term but i get the following error.

Msg 206, Level 16, State 2, Line 19
Operand type clash: date is incompatible with int

推荐答案

set @strt=@strt-1

导致了此问题,因为您尝试从日期中减去1.使用 DATEADD [ ^ ]如果要减去一天.

看看 DATEDIF [ ^ ],以获得更好的计算天数的方法.

is causing the problem because you are try to subtract 1 from a date. Use DATEADD[^] if you want to subtract one day.

Have a look at DATEDIF[^] for a better way to calculate the number of days.



这篇关于如何计算一个学期中不包括周末的总天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 21:05