Sp EF输出 临时表
-- =============================================
-- 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输出 临时表的更多相关文章
- ps -ef 输出具体含义
ps -ef 输出具体含义 UID PID PPID C STIME TTY TIME CMD 各相关信息的意义: UID 程序被该 UID 所拥有 PID 就是这 ...
- 关于EF输出sql的执行日志
sqlserver中可以使用sql profiler:但是mysql当中无法查看:只能借助于组件: ADO.NET Entity Framework CodeFirst 如何输出日志(EF4.3) 用 ...
- Linux—ps -ef 命令输出信息的具体含义(显示所有正在运行的命令程序)
linux 中使用 ps -ef 输出参数的具体含义 功能:显示所有正在运行的命令程序 UID: 说明该程序被谁拥有PID:就是指该程序的 IDPPID: 就是指该程序父级程序的 IDC: 指的是 C ...
- mysql sp 练习游标和预编译
create procedure Jack_count_cur_dual() BEGIN ); ; DECLARE mycur CURSOR for SELECT table_name FROM tt ...
- MVC教程--MiniProfiler.EF监控调试MVC和EF的性能
上一篇谈到mvc中ef输出执行sql日志:来谈用mvc开发项目的调试和性能监控.EF框架自动给我生成sql语句,当我们的程序遇到性能问题的时候我们可以用MiniProfiler.EF来监控调试MVC和 ...
- 【Linux】ps -ef 和ps aux 的区别
Linux下显示系统进程的命令ps,最常用的有ps -ef 和ps aux.这两个到底有什么区别呢?两者没太大差别,讨论这个问题,要追溯到Unix系统中的两种风格,System V风格和BSD 风格, ...
- 01-Linux操作系统+指令
一.Linux操作系统 操作系统定义:操作系统直接运行在计算机上的系统软件, 它是与硬件打交道和控制软件运行的计算机程序. 虚拟机:就是模拟一个真实的计算机,好比一个虚拟的电 ...
- (2.2)DDL增强功能-自定义函数与存储过程
1.存储过程 精华总结: 通过对比@@ERROR一般和if判断结合使用,@@TRANCOUNT和try catch块结合使用,xact_abort为on可以单独使用Xact_abort为off时,如果 ...
- Linux进程管理及while循环
目录 进程的相关概念 进程查看及管理工具的使用 Linux系统作业控制 调整进程优先级 网络客户端工具 bash之while循环 20.1.进程类型 守护进程 daemon,在系统引导过程中启动的进程 ...
随机推荐
- LINQ查询数组里面是否包含某值
#region linq to 数组 //定义数组,并初始化 string [] array = new string []{"Juan" ...
- poj 1035
http://poj.org/problem?id=1035 poj的一道字符串的水题,不难,但就是细节问题我也wa了几次 题意就是给你一个字典,再给你一些字符,首先如果字典中有这个字符串,则直接输出 ...
- svn迁移到git仓库并保留commit历史记录
svn迁移到git仓库并保留commit历史记录 最近在做svn迁移到gitlab,由于之前一直是由svn做版本控制.最简单的方式是将svn的内容export出来,然后添加到gitlab即可.但是,如 ...
- nyoj221_Tree_subsequent_traversal
Tree 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Little Valentine liked playing with binary trees very ...
- Divide and conquer:Dropping tests(POJ 2976)
最大化平均值 题目大意:给定你n个分数,从中找出k个数,使∑a/∑b的最大值 这一题同样的也可以用二分法来做(用DP会超时,可见二分法是多么的实用呵!),大体上是这样子:假设最大的平均值是w,那么题目 ...
- 表现层的设计(一)——常用的模式、Json与DTO
上几篇博文介绍了 业务逻辑层和数据访问层,我认为写博文的作用主要是向业界的读者交流一种思想,点到为止,至于学习架构设计,通过几篇博文是讲不清楚的,还需要[基础]扎实的情况下,[反复]研究[权威]的书籍 ...
- ATS(App Transport Security)对HTTP协议屏蔽引起的问题
一.问题描述 在学习网络处理的过程,发现代码都没错,运行时会收到如下错误提示: App Transport Security has blocked a cleartext HTTP (http:// ...
- 【leetcode】Remove Duplicates from Sorted Array I & II(middle)
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- rabbitmq_config
https://github.com/rabbitmq/rabbitmq-server/blob/stable/docs/rabbitmq.config.example %% ---------- ...
- 20145206《Java程序设计》实验五Java网络编程及安全
20145206<Java程序设计>实验五 Java网络编程及安全 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 实验步骤 我和201451 ...