SqlServer 存储过程 if else 两层判断 语句拼接
2011-02-24 11:54
399 查看
今天自己摸索写了一个sql的存储过程,两层if 判断,语句拼接,backup
语句模式有两种,一种是Create New 还有一种是Modify ,下面的是第一种
要提示的是,写语句的时候 单引号的引用:用到单引号的一律两个单引号代替
语句模式有两种,一种是Create New 还有一种是Modify ,下面的是第一种
要提示的是,写语句的时候 单引号的引用:用到单引号的一律两个单引号代替
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 exec(@sql) END
相关文章推荐
- 一道腾讯的笔试题,不使用任何判断语句求出两个数中的较大者(即 if、if...else...、>、<、==、while等语句)
- JS中最简单的判断语句if else
- 【九度1506】求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 【算法题】题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)
- C_判断语句if与else的组合使用
- 条件判断语句(if...else)与条件编译(#if .... #else ... #endif)
- linux shell if else 多个选择条件的判断语句 语法
- shell 判断语句 if else
- 求1+2+…+n, 要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)
- 求1+2+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A? B:C)
- SQL Server判断语句(IF ELSE/CASE WHEN )
- 求1+2+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句
- 求1+2+…+n 要求不能使用 乘 除 法、for、while、if、else、switch、case等关键字以及条件判断语句
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)
- 判断语句switch - case 和if - else
- C/C++学习(一)题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。
- 【PHP之If…Else 条件判断语句】
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
- 每天学习一算法系列(12) (求1+2+…+n,不能使用乘除法,for、while、if 、else、switch、case 等关键字以及条件判断语句)
- 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。