日期:2014-05-17 浏览次数:50706 次
declare @dateTime datetime
declare @startTime datetime
declare @endTime datetime
declare @wname nvarchar
set @dateTime='2013-11-13'
set @wname='www.baidu.com'
set @startTime=convert(char(4),datepart(yyyy,@dateTime))+'-01-01'
set @endTime=dateadd(yyyy,1,@startTime)
select sum(readCount) as readtotal,convert(char(7),comdatetime,20)+'-01' as payt
from WebUserFrom where webFrom=@wname and comdatetime<@endTime and comdatetime>@startTime group by convert(char(7),comdatetime,20)
declare @dateTime datetime
declare @startTime datetime
declare @endTime datetime
declare @wname nvarchar
set @dateTime='2013-11-13'
set @wname='www.baidu.com'
set @startTime=convert(char(4),datepart(yyyy,@dateTime))+'-01-01'
set @endTime=dateadd(yyyy,1,@startTime)
select sum(readCount) as readtotal,convert(char(7),comdatetime,20)+'-01' as payt
from WebUserFrom where webFrom=@wname and comdatetime<@endTime and comdatetime>@startTime group by convert(char(7),comdatetime,20)+'-01'
declare @dateTime datetime
declare @startTime datetime
declare @endTime datetime
declare @wname nvarchar
set @dateTime='2013-11-13'
set @wname='www.baidu.com'
set @startTime=convert(char(4),datepart(yyyy,@dateTime))+'-01-01'
set @endTime=dateadd(yyyy,1,@startTime)
select sum(readCount) as readtotal,convert(char(7),comdatetime,20)+'-01' as payt
from WebUserFrom
where webFrom=@wname and comdatetime<@endTime and comdatetime>@startTime
group by convert(char(7),comdatetime,20)+'-01'
declare @dateTime datetime
declare @startTime datetime
declare @endTime datetime
declare @wname nvarchar(100) --由于你定义的变量长度不够,会导致下面赋值时,值被截断
set @dateTime='2013-11-13'
set @wname='www.baidu.com' --nvarchar时,值会被截断
set @startTime=convert(char(4),datepart(yyyy,@dateTime))+'-01-01'
set @endTime=dateadd(yyyy,1,@startTime)
--这里group by和select中的必须要一样
select sum(readCount) as readtotal,
convert(char(7),comdate