`
java032
  • 浏览: 86803 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

存储过程的拼接写法 -- 转载

 
阅读更多
USE [a]
GO
/****** Object:  StoredProcedure [a].[Processname]    Script Date: 02/24/2011 11:49:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [a].[Processname]
@FromDateTime varchar(200),
@ToDateTime varchar(200),
@CountryCode varchar(200),
@Version varchar(200)
AS
declare @sql varchar(1000)
set @sql='select AccessDateTime,IpAddress,Area,AreaDetail as description,City,Version from a.TableName where AccessDateTime
 between ''' + @FromDateTime+''' and '''+ @ToDateTime+''''
BEGIN
	if(@CountryCode='')
	begin
		set @sql=@sql
		if(@Version='')
			begin
				set @sql = @sql +' order by id desc'
			end
		else
			begin
				set @sql = @sql + ' and  Version='''+@Version +'''  order by id desc'
			end
	end
	else 
	begin
		set @sql=@sql
		if(@Version='')	
			begin
				set @sql=@sql +' and  Area='''+@CountryCode+''' order by id desc'
			end	
		else
			begin
				set @sql=@sql +' and Area='''+@CountryCode+''' and  Version='''+ @Version +''' order by id desc'
			end
	end	
--print @sql	
exec(@sql)	
END


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics