-- =============================================
-- 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. Unity关于用LoadLevelAdditiveAsync导致新场景的Navmesh数据不正确Loading条的实践

    为了解决用Application.LoadLevelAdditiveAsync 导致新场景的Navmesh数据不正确(我们用的是4.63),我们现在loading条做法是先切到Loading的场景,然 ...

  2. Unity3d《Shader篇》描边

    Shader "Custom/OutLine" {Properties { _Color ("Main Color", Color) = (.5,.5,.5,1 ...

  3. FFmpeg-20160415-snapshot-bin

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 F ...

  4. 【leetcode】triangle(easy)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  5. orace 取昨天凌晨的日期

    sysdate 为现在时间sysdate-1为昨天trunc(sysdate-1)为昨天凌晨0:00trunc(sysdate-1)+20/24 为昨天晚上8点select trunc(sysdate ...

  6. CSS命名格式

    CSS样式命名整理页面结构 容器: container/wrap整体宽度:wrapper页头:header内容:content页面主体:main页尾:footer导航:nav侧栏:sidebar栏目: ...

  7. iOS - UIButton设置图片文字上图下文排列

    经查阅资料及尝试,最终解决了在图片和文字垂直排列的情况下,如果文字长度变化会导致图片位置变动的问题,最开始采用了网上比较多的做法,做法如下: @interface UIButton (UIButton ...

  8. JavaScript基础——创建函数

    JavaScript的最重要的一个部分是制作其他代码可以重用的代码.要做到这一点,你可以把代码组织成执行特定任务的函数.函数是结合在一个单一的块中,并给予一个名称的一系列代码语句.然后,你就可以通过引 ...

  9. 苹果官方制作MAC OS的启动U盘的步骤

    工具/原料 一个8G或者更大容量的U盘 MAC OS系统镜像DMG文件 方法/步骤 1.打开应用程序 - 使用工具里的磁盘工具,将U盘格式化为MAC OS扩展日志式,名称输入Mavericks,并创建 ...

  10. orcad 元件库的查找位置对照表

    orcad元件库的查找: 如下:1.原理图常用库文件: MiscellaneousDevices.ddb: DallasMicroprocessor.ddb: IntelDatabooks.ddb: ...