控件中国网现已改版,您看到的是老版本网站的镜像,系统正在为您跳转到新网站首页,请稍候.......
中国最专业的商业控件资讯网产品咨询电话:023-67870900 023-67871946
产品咨询EMAIL:SALES@COMPONENTCN.COM

SP ROW_NUMBER()

作者:佚名 出处:互联网 2011年12月02日 阅读:

SP ROW_NUMBER()

USE [AppServices]
GO
/****** Object:  StoredProcedure [dbo].[Batch_GetNonTransferableMembers_p]    Script Date: 07/06/2011 11:24:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE [dbo].[Batch_GetNonTransferableMembers_p] 
      @Batch_id AS INT 
    , @IsIncludeDetail AS BIT 
AS 
-- ============================================= 
-- Author:  Richard.Chen 
-- Create date: 2011/5/30 
-- Description: ALTER PROCEDURE Batch_GetNonTransferableMembers_p for task 28652 
-- Returns Non-Transferable member count of the specified batch by default, and return details as well if @IsIncludeDetail is true 
-- =============================================  
 
-- Save Transferable BatchItem into #temp table 
SELECT b.BatchItem_id INTO #temp 
 FROM AppServices.dbo.BatchItem AS b WITH (NOLOCK) 
  INNER JOIN ET_Commerce.dbo.Subscriptions AS s WITH (NOLOCK) ON s.MemberId = b.Member_id 
  INNER JOIN ET_Commerce.dbo.Redemptions AS r WITH (NOLOCK) ON r.Code = s.PromoCode 
  INNER JOIN ET_Commerce.dbo.Licenses AS l WITH (NOLOCK) ON l.LicenseId = r.LicenseId 
 WHERE b.Batch_id = @Batch_id 
  AND b.IsDeleted = 0 
  AND b.Member_Id IS NOT NULL 
  AND s.IsActive = 1 
  AND l.IsTransferable = 1 
 
-- Return NonTransferable member count 
SELECT COUNT(1) FROM dbo.BatchItem WITH (NOLOCK)  
 WHERE Batch_id = @Batch_id
  AND IsDeleted = 0 
  AND BatchItem_id NOT IN (SELECT BatchItem_id FROM #temp) 
 
-- Return NonTransferable member details if @IsIncludeDetail is true 
IF @IsIncludeDetail = 1 
BEGIN 
    ;WITH CTE AS
    (
         SELECT DISTINCT b.Member_id 
              , Email =  CASE  
                            WHEN m.Email IS NULL THEN b.Email  COLLATE SQL_Latin1_General_CP1_CI_AS
                            ELSE m.Email 
                         END 
              , r.Code AS LicenseCode 
              , cd.DivisionCode  
              , ROW_NUMBER() OVER (PARTITION BY m.MemberId ORDER BY s.SubscriptionId DESC) AS num
          FROM AppServices.dbo.BatchItem AS b WITH (NOLOCK) 
           LEFT JOIN ET_Main.dbo.Members AS m WITH (NOLOCK) ON m.MemberId = b.Member_id 
           LEFT JOIN ET_Commerce.dbo.Subscriptions AS s WITH (NOLOCK) ON s.MemberId = b.Member_id
           LEFT JOIN ET_Commerce.dbo.Redemptions AS r WITH (NOLOCK) ON r.Code = s.PromoCode COLLATE SQL_Latin1_General_CP1_CI_AS 
           LEFT JOIN ET_Commerce.dbo.Licenses AS l WITH (NOLOCK) ON l.LicenseId = r.LicenseId 
           LEFT JOIN ET_Corporate.dbo.CorporateMembers AS cm WITH (NOLOCK) ON cm.MemberId = b.Member_id 
           LEFT JOIN ET_Corporate.dbo.CorporateDivision AS cd WITH (NOLOCK) ON cd.DivisionId = cm.DivisionId 
          WHERE b.Batch_id = @Batch_id 
           AND b.IsDeleted = 0
           AND b.BatchItem_id NOT IN (SELECT BatchItem_id FROM #temp) 
       )
      
       SELECT Member_id, Email, LicenseCode, DivisionCode FROM CTE WHERE num = 1
END 
 
RETURN 

GO
GRANT EXECUTE ON [dbo].[Batch_GetNonTransferableMembers_p] TO [CommerceBaseRole] AS [dbo]

SELECT * INTO temp FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=c:/人员信息.xls',sheet1$)

 

热推产品

  • ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
  • AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
首页 | 新闻中心 | 产品中心 | 技术文档 | 友情连接 | 关于磐岩 | 技术支持中心 | 联系我们 | 帮助中心 Copyright-2006 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 电话:023 - 67870900 传真:023 - 67870270 产品咨询:sales@componentcn.com 渝ICP备12000264号 法律顾问:元炳律师事务所 重庆市江北区塔坪36号维丰创意绿苑A座28-5 邮编:400020
在线客服
在线客服系统
在线客服
在线客服系统