search
Homephp教程PHP开发SQL statement splicing in SQL stored procedures

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

-- ================================== ===========

-- Author:wgh

-- Create date: 2012-06-07

-- Description: IP access pre-statistics

-- ====== =======================================

CREATE PROCEDURE [dbo].[PROC_HB_PreStatByIP]

@BeginTime varchar(50),

@EndTime varchar(50),

@TimeType int, --0 represents hours, 1 represents days

@ChannelID varchar(10)='0',

@I pAddress varchar(20)

AS

BEGIN

declare @sql1 nvarchar(2000)

IF @TimeType = 0

BEGIN

SET @sql1='SELECT CONVERT(varchar(13),AddTime ,120) AS ' 'Date''

,ChannelID AS ''Promotion channel''

,IPAddress AS ''IP address''

,ViewCount AS ''Number of views''

​​​​​​​,ClickCount AS ''Number of clicks''

FROM dbo.HB_AdPreStatIP WHERE AddTime>='''+@BeginTime+''' AND AddTime

                                                                                                                                               sql1 =@sql1 + ' AND ChannelID='''+@ChannelID+''''

                                                                                                                 1 +' AND IPAddress=' ''+@IpAddress+''''

    END

      SET @sql1 =@sql1+' ORDER BY ViewCount DESC' END

                           'SELECT CONVERT(varchar(10), AddTime,120) AS ''Date''

,ChannelID AS ''Promotion channel''

,IPAddress AS ''IP address''

,              , SUM(ViewCount) AS                                                                                                                                                                                 , SUM (ViewCount) (ClickCount) AS ''Number of clicks''

                                                                                  ‐ ‐ ‐ ‐ ‑ ‑ ‐ ‐ dbo.HB_AdPreStatIP WHERE ​'0'

                                                                                                                                                         

                                                                                                                                                                                                                                                                                                      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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor