-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[USP_PM_SearchPatronByCriteria]
@IsActive bit = NULL,
@PatronNo bigint=NULL,
@BirthDate date=NULL,
@PNFirstName nvarchar()=NULL,
@PNLastName nvarchar()=NULL,
@Gender nvarchar()=NULL,
@MobileCountryCode nvarchar()=NULL,
@Mobile nvarchar()=NULL,
@Email nvarchar()=NULL,
@MembershipClass nvarchar()=Null,
@IDType nvarchar()=NULL,
@IDNumber nvarchar()=NULL,
@CountryID smallint=NULL,
@CityName nvarchar()=NULL,
@DocType nvarchar(),
@Page int = ,
@PageSize int = ,
@OrderSQL nvarchar(max)=null,
@TotalRow int output -- Add the parameters for the stored procedure here
as
BEGIN
SET NOCOUNT ON;
SET FMTONLY OFF declare @PatronSqlWhereCommand nvarchar(Max)
declare @IdentificationAndAddressSqlWhereCommand nvarchar(Max) declare @SQL nvarchar(Max)
declare @PageCommand nvarchar(Max) declare @GetTotalRowSQL nvarchar(Max) declare @Result nvarchar(Max)
declare @Start nvarchar(Max)
declare @End nvarchar(Max) -- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements. SET @PatronSqlWhereCommand = ' where 1=1';
SET @IdentificationAndAddressSqlWhereCommand= ' where 1=1'; if(@PageSize is null or @PageSize=)
begin
SET @PageSize=;
end
if(@Page is null)
begin
SET @Page=;
end if(@OrderSQL is null or @OrderSQL='')
begin
SET @OrderSQL='ModifiedDate desc';
end if(@DocType is null)
begin
SET @DocType='';
end SET @Start=CONVERT(nvarchar(),(@Page-)*@PageSize+);
SET @End=CONVERT(nvarchar(),(@Page)*@PageSize); --
if(@IsActive is not Null)
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND IsActive=',@IsActive);
end
--
if(@PatronNo is not Null)
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND Patron_No=',@PatronNo);
end
--
if(@BirthDate is not Null)
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND Birth_Date=',@BirthDate);
end
--
if(@PNFirstName is not Null and @PNFirstName <> '')
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND PN_First_Name like ''%',@PNFirstName,'%''');
end
--
if(@PNLastName is not Null and @PNLastName <> '')
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND PN_Last_Name like ''%',@PNLastName,'%''');
end
--
if(@Gender is not Null and @Gender <> '')
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND Gender=''',@Gender,'''');
end
--
if(@MobileCountryCode is not Null and @MobileCountryCode <> '')
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND Mobile_Country_Code=''',@MobileCountryCode,'''');
end
--
if(@Mobile is not Null and @Mobile <> '')
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND Mobile_No=''',@Mobile,'''');
end
--
if(@Email is not Null and @Email <> '')
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND eMail like ''%',@Email,'%''');
end
--
if(@MembershipClass is not Null and @MembershipClass <> '')
begin
SET @PatronSqlWhereCommand =concat(@PatronSqlWhereCommand,' AND Membership_Class=''',@MembershipClass,'''');
end
--
if(@IDType is not Null and @IDType <> '')
begin
SET @IdentificationAndAddressSqlWhereCommand =concat(@IdentificationAndAddressSqlWhereCommand,' AND I.ID_Type=''',@IDType,'''');
end
--
if(@IDNumber is not null or @IDNumber = '')
begin
SET @IdentificationAndAddressSqlWhereCommand =concat(@IdentificationAndAddressSqlWhereCommand,' AND I.ID_No=''',@IDNumber,'''');
end
--
if(@CountryID is not Null)
begin
SET @IdentificationAndAddressSqlWhereCommand =concat(@IdentificationAndAddressSqlWhereCommand,' AND A.Country_ID=',@CountryID);
end
--
if(@CityName is not null or @CityName = '')
begin
SET @IdentificationAndAddressSqlWhereCommand =concat(@IdentificationAndAddressSqlWhereCommand,' AND A.City_Name like ''%',@CityName,'%''');
end SET @SQL='select P.*,I.ID_Type,I.ID_No,A.Country_ID,A.City_Name,DD.File_Name,(Isnull(I.Modified_Date,I.Created_Date)) as ISort_Date,(Isnull(A.Modified_Date,A.Created_Date)) as ASort_Date
into #patronDetail
from (select * from GSMA_Patron '+@PatronSqlWhereCommand+' ) P
left join GSMA_Patron_Identification I on P.Patron_ID=I.Patron_ID and I.IsActive=''true''
left join GSMA_Patron_Address A on P.Patron_ID=A.Patron_ID and A.IsActive=''true''
left join (select * from GSAL_Document_Detail where Doc_Type='''+@DocType+''' and IsActive=''true'')
DD on P.Doc_ID=DD.Doc_ID '+@IdentificationAndAddressSqlWhereCommand+' '+' select ar1.Patron_ID as PatronID,
ar1.Patron_No as PatronNo,
ar1.Property_ID as PropertyID,
ar1.Doc_ID as DocID,
ar1.PN_Prefix as PNPrefix,
ar1.PN_First_Name as PNFirstName,
ar1.PN_Middle_Name as PNMiddleName,
ar1.PN_Last_Name as PNLastName,
ar1.PN_Suffix as PNSuffix,
ar1.EX_Prefix as EXPrefix,
ar1.EX_First_Name as EXFirstName,
ar1.EX_Middle_Name as EXMiddleName,
ar1.EX_Last_Name as EXLastName,
ar1.EX_Suffix as EXSuffix,
ar1.Birth_Date as BirthDate,
ar1.Birth_City as BirthCity,
ar1.Patron_Country as PatronCountry,
ar1.Gender as Gender,
ar1.Preferred_Name as PreferredName,
ar1.Display_Name as DisplayName,
ar1.Occupation as Occupation,
ar1.Communication_Lang_Id as CommunicationLangId,
ar1.Junket_Operator_ID as JunketOperatorID,
ar1.Player_Type as PlayerType,
ar1.Membership_Class as MembershipClass,
ar1.Mail_Code as MailCode,
ar1.Registration_Source as RegistrationSource,
ar1.Security_Level as SecurityLevel,
ar1.Signup_Host as SignupHost,
ar1.Mobile_Country_Code as MobileCountryCode,
ar1.Mobile_No as MobileNo,
ar1.Home_Phone_Country_Code as HomePhoneCountryCode,
ar1.Home_Phone_No as HomePhoneNo,
ar1.Business_Phone_Country_Code as BusinessPhoneCountryCode,
ar1.Business_Phone_No as BusinessPhoneNo,
ar1.Fax_Country_Code as FaxCountryCode,
ar1.Fax_No as FaxNo,
ar1.eMail as eMail,
ar1.Height_Unit as HeightUnit,
ar1.Height as Height,
ar1.Weight_Unit as WeightUnit,
ar1.Weight as Weight,
ar1.Hair_Color as HairColor,
ar1.Eye_Color as EyeColor,
ar1.Excluded_Purge_Validity as ExcludedPurgeValidity,
ar1.Exclude_Purge_Flag as ExcludePurgeFlag,
ar1.Send_SMS_Flag as SendSMSFlag,
ar1.Send_Email_Flag as SendEmailFlag,
ar1.Ancillary_Account_Flag as AncillaryAccountFlag,
ar1.IsPurged as IsPurged,
ar1.IsLinked as IsLinked,
ar1.IsMerged as IsMerged,
ar1.IsActive as IsActive,
ar1.Last_Active_Date as LastActiveDate,
ar1.Row_Version as RowVersion,
ar1.Device_ID as DeviceID,
ar1.Created_Date as CreatedDate,
ar1.Created_By as CreatedBy,
ar1.Modified_By as ModifiedBy,
ar1.Modified_Date as ModifiedDate,
ar1.ID_Type as IDType,
ar1.ID_No as IDNo,
ar1.Country_ID as CountryID,
ar1.City_Name as CityName,
ar1.File_Name as FileName into #PatronData from (select * from #patronDetail) ar1
inner join (select a.Patron_ID,MAX(a.ISort_Date)as Date1 from #patronDetail a group by a.Patron_ID) ar2
on ar1.Patron_ID=ar2.Patron_ID and isnull(ar1.ISort_Date,GETDATE())=isnull(ar2.Date1,GETDATE())
inner join (select a.Patron_ID,MAX(a.ASort_Date)as Date2 from #patronDetail a group by a.Patron_ID) ar3
on ar1.Patron_ID=ar3.Patron_ID and isnull(ar1.ASort_Date,GETDATE())=isnull(ar3.Date2,GETDATE()) '; SET @GetTotalRowSQL='Select @Rows=count(1) from #PatronData;'; SET @Result=@SQL+@GetTotalRowSQL; Execute sp_executesql @Result, N'@Rows int output', @TotalRow output; SET @SQL=@SQL+
' select r.*,
G.Lkp_Value as GenderName,
M.Lkp_Value as MembershipClassName,
I.Lkp_Value as IDTypeName,
C.Country_Name as CountryName
into #result
from #PatronData r
left join GSRE_GenLKP G on r.Gender =G.Lookup_Cd
left join GSRE_GenLKP M on r.MembershipClass =M.Lookup_Cd
left join GSRE_GenLKP I on r.IDType =I.Lookup_Cd
left join GSRE_Country C on r.CountryID =C.Country_ID select * from (
select ROW_NUMBER() over (order by '+@OrderSQL+') as row_number,* from #result
) result';
--fix EF bug
if(isnull(@Start,'') =''or isnull(@End,'') ='')
begin
SET @PageCommand=' ';
end
else
begin
if(@TotalRow<@PageSize)
begin
SET @PageCommand=' ';
end
else
begin
SET @PageCommand=' where result.Row_number BETWEEN '+@Start+' AND '+@End;
end
end --------------------------------- SET @Result=@SQL+@PageCommand; exec(@Result); END

SET FMTONLY OFF

这样设置了就不会输出是int。。而是输出临时表了

Sp EF输出 临时表的更多相关文章

  1. ps -ef 输出具体含义

    ps -ef 输出具体含义 UID        PID  PPID  C STIME TTY          TIME CMD 各相关信息的意义: UID 程序被该 UID 所拥有 PID 就是这 ...

  2. 关于EF输出sql的执行日志

    sqlserver中可以使用sql profiler:但是mysql当中无法查看:只能借助于组件: ADO.NET Entity Framework CodeFirst 如何输出日志(EF4.3) 用 ...

  3. Linux—ps -ef 命令输出信息的具体含义(显示所有正在运行的命令程序)

    linux 中使用 ps -ef 输出参数的具体含义 功能:显示所有正在运行的命令程序 UID: 说明该程序被谁拥有PID:就是指该程序的 IDPPID: 就是指该程序父级程序的 IDC: 指的是 C ...

  4. mysql sp 练习游标和预编译

    create procedure Jack_count_cur_dual() BEGIN ); ; DECLARE mycur CURSOR for SELECT table_name FROM tt ...

  5. MVC教程--MiniProfiler.EF监控调试MVC和EF的性能

    上一篇谈到mvc中ef输出执行sql日志:来谈用mvc开发项目的调试和性能监控.EF框架自动给我生成sql语句,当我们的程序遇到性能问题的时候我们可以用MiniProfiler.EF来监控调试MVC和 ...

  6. 【Linux】ps -ef 和ps aux 的区别

    Linux下显示系统进程的命令ps,最常用的有ps -ef 和ps aux.这两个到底有什么区别呢?两者没太大差别,讨论这个问题,要追溯到Unix系统中的两种风格,System V风格和BSD 风格, ...

  7. 01-Linux操作系统+指令

    一.Linux操作系统     操作系统定义:操作系统直接运行在计算机上的系统软件, 它是与硬件打交道和控制软件运行的计算机程序.          虚拟机:就是模拟一个真实的计算机,好比一个虚拟的电 ...

  8. (2.2)DDL增强功能-自定义函数与存储过程

    1.存储过程 精华总结: 通过对比@@ERROR一般和if判断结合使用,@@TRANCOUNT和try catch块结合使用,xact_abort为on可以单独使用Xact_abort为off时,如果 ...

  9. Linux进程管理及while循环

    目录 进程的相关概念 进程查看及管理工具的使用 Linux系统作业控制 调整进程优先级 网络客户端工具 bash之while循环 20.1.进程类型 守护进程 daemon,在系统引导过程中启动的进程 ...

随机推荐

  1. 【leetcode】Valid Number

    Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...

  2. wx.ListCtrl简单使用例子

    效果图: 示例代码: #! /usr/bin/env python #coding=utf-8 import wx import sys packages = [('jessica alba', 'p ...

  3. Android之EditText自定义边框和边框颜色(转载)

    介绍一种比较常见的用法 第一步:准备两张图片大小一样,颜色不同的图片.图片名称分为:editbox_focus.png和editbox_normal.png 放入工程的drawable文件夹下. 第二 ...

  4. mysql开启binlog

    mysql开启binlog,至于为什么要开启binlog,可以google下. ## 设置server_id,一般设置为IP server_id= ## 复制过滤:需要备份的数据库名,多个库以逗号分隔 ...

  5. Java RuntimeException异常处理汇总

    Java中所有异常的父类是Throwable类,在Throwable类下有两大子类: 一个是Error类,指系统错误异常,例如:VirtualMachineError 虚拟机错误,ThreadDeat ...

  6. Java数组的复制Arrays.copyOf()、System.arraycopy()、nums.clone()

    public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length); a ...

  7. Effective C++ -----条款43:学习处理模板化基类内的名称

    可在derived class templates内通过“this->“指涉base class templates内的成员名称,或藉由一个明白写出的”base class资格修饰符”完成.

  8. Match:Power Strings(POJ 2406)

     字符串前缀的阶 题目大意:求前缀的阶 和POJ1961是一样的,KMP的Next数组的应用,不要用STL,不要一个一个读入字符(IO永远是最慢的) #include <iostream> ...

  9. Xcode无法启动ios模拟器的问题

    一.问题描述 开发过程需要来回切换ios模拟器调试程序,开始在iPhone 4s下调试,然后切换到iPhone 6s Plus,再切换回iPhone 4s,遇到无法启动ios模拟器.错误提示如下: 二 ...

  10. 【leetcode】Remove Element (easy)

    Given an array and a value, remove all instances of that value in place and return the new length. T ...