Home php教程 PHP开发 SQL statement splicing in SQL stored procedures

SQL statement splicing in SQL stored procedures

Dec 14, 2016 pm 03:22 PM

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<='''+@EndTIme+'''

                                                                                                                                               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 of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)