--Query the number of tickets that a specified vendor has specified for a period of time
If every query one months, modify a time too troublesome, write a cycle!
DECLARE @date1 date
DECLARE @date2 date
DECLARE @startdate date
DECLARE @enddate date
DECLARE @countsum int
DECLARE @count int
Set @startdate = ' 2010-06-01 '
Set @enddate = ' 2011-07-01 '
Set @count =1
Set @countsum =datediff (MM, @startdate, @enddate)
Set @date1 = @startdate
Set @date2 =dateadd (mm,1, @startdate)
While @count < @countsum
Begin
--Execute SQL
SELECT SUM (Passengercount) as number from dbo. Orders WHERE ProviderID =
(SELECT UserId from dbo.) User
WHERE username= ' wind2006 ')
and Ordertime Between @date1 and @date2
Set @date1 =dateadd (mm,1, @date1)
Set @date2 =dateadd (mm,1, @date2)
Set @count = @count +1
End
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/