-- =============================================
-- 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. zju3547

    题意:给出n(1<=n<=10^8),求小于n的,求所有与n互质的数字的四次幂的加和是多少. 分析:容斥原理 首先要知道四次幂求和公式,1^4+2^4+...+n^4=n*(n+1)*(2 ...

  2. Linux下安装gcc和g++

    以CentOS为例,安装后是没有C语言和C++编译环境的,需要手动安装,最简单的是用yum的方式安装,过程如下: 1.安装gcc yum install gcc 询问是否,按y键回车即可,或者 yum ...

  3. ACM/ICPC 之 最短路-SPFA+正逆邻接表(POJ1511(ZOJ2008))

    求单源最短路到其余各点,然后返回源点的总最短路长,以构造邻接表的方法不同分为两种解法. POJ1511(ZOJ2008)-Invitation Cards 改变构造邻接表的方法后,分为两种解法 解法一 ...

  4. 16. javacript高级程序设计-HTML5脚本编程

    1. HTML5脚本编程 l 跨文档消息传递API能够让我们在不降低同源策略安全性的前提下,在来至不同的域的文档间传递消息 l 原生拖放功能可以方便的指定某个元素是否可以拖动,并在放置时做出响应.还可 ...

  5. MongoDB 查询优化分析

    摘要: 在MySQL中,慢查询日志是经常作为我们优化查询的依据,那在MongoDB中是否有类似的功能呢?答案是肯定的,那就是开启Profiling功能.该工具在运行的实例上收集有关MongoDB的写操 ...

  6. 汉企学习4个半月的target and plan

    我自从大学毕业以后,工作飘忽不定,其中也不乏有我自己的原因.IT是我向往的行业,几经波折,我来到了汉企. 9月4号,算是正式与汉企接触的第一天.在这里,我看到了学员的上进,老师的责任心,让我感受颇深. ...

  7. SQL如何本地数据库连接服务器的数据库

    当我们本地数据库的数据作为测试的时候,需要服务器上的数据,但是每次都远程服务器打开数据库查看数据是很麻烦的,那么我们如何让本地的数据库连接服务器上的数据库.前提是你本地的数据库的版本必须和服务器上的数 ...

  8. webstorm配置scss自动编译路径

    webstorm支持sass的同步编译,也就是即写即编译,并且可以指定编译后的css的目录. 本文使用的webstorm为8.0版本 scss安装:http://www.w3cplus.com/sas ...

  9. javascript测试

    s阿道夫. 撒旦法 sd sad sd 的萨法a dsa发 fds sdfad 电风扇爱的方式爱的方式啊

  10. android bitmap的放大缩小

    private static Bitmap big(Bitmap bitmap) { Matrix matrix = new Matrix(); matrix.postScale(1.5f,1.5f) ...