ANSI_NULLS auf EIN setzen
QUOTED_IDENTIFIER auf EIN setzen
go
-- ==================== ========================
-- Autor:wgh
-- Erstellungsdatum: 2012-06 -07
-- Beschreibung: IP-Zugriffsvorstatistik
-- ========================= = ===================
PROZEDUR ERSTELLEN [dbo].[PROC_HB_PreStatByIP]
@BeginTime varchar(50),
@EndTime varchar(50),
@TimeType int, --0 steht für Stunden, 1 steht für Tage
@ChannelID varchar(10)='0',
@IpAddress varchar(20)
AS
BEGIN
deklariere @sql1 nvarchar(2000)
IF @TimeType = 0
BEGIN
SET @sql1='SELECT CONVERT(varchar(13),AddTime,120) AS ''Datum''
,ChannelID AS ''Werbekanal''
,IPAddress AS ''IP-Adresse''
,ViewCount AS ''Anzahl der Aufrufe''
,ClickCount AS ''Anzahl der Klicks''
FROM dbo .HB_AdPreStatIP WHERE AddTime>='''+@BeginTime+''' AND AddTime<='''+@EndTIme+''''
IF @ChannelID <> '0'
BEGIN
SET @sql1 =@sql1 + ' AND ChannelID='''+@ChannelID+''''
END
IF @IpAddress < > '
BEGIN
SET @sql1 =@sql1 +' AND IPAddress='''+@IpAddress+''''
END
SET @ sql1 =@sql1+' ORDER BY ViewCount DESC'
END
ELSE
BEGIN
SET @sql1='SELECT CONVERT(varchar(10 ), AddTime,120) AS ''Datum''
,ChannelID AS ''Promotion Channel''
,IPAddress AS ''IP Address''
,SUM (ViewCount ) AS ''Views''
,SUM(ClickCount) AS ''Clicks''
FROM dbo.HB_AdPreStatIP WHERE AddTime>='''+@ BeginTime+''' AND AddTime<='''+@EndTIme+''''
IF @ChannelID > '0'
BEGIN
SET @sql1 =@sql1 + ' AND ChannelID ='''+@ChannelID+''''
END
IF @IpAddress <> ''
BEGIN
SET @sql1 = @sql1 +' AND IPAddress='''+@IpAddress+''''
END
SET @sql1 =@sql1 + 'GROUP BY CONVERT(varchar(10),AddTime,120 ),ChannelID,IPAddress ORDER BY SUM(ViewCount) DESC'
END
EXEC sp_executesql @sql1
END