优化存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author:?? ??? ?ylem
-- Create date: 2010-04-15
-- Description:?? ?N天老隊銷售未跟進的客戶
-- =============================================
ALTER PROCEDURE [dbo].[Proc_GetCustomerIDByNoAwoke]
?? ?@orgId int --分公司ID
AS
BEGIN
??? declare @strDay varchar(32)
??? select @strDay = settingvalue from SystemSettings where OrganizationID=@orgId and SettingKey=25
?? ?if(@strDay is not null)
?? ?begin
?? ??? ?declare @day int
?? ??? ?set @day=cast(@strDay as int)
?? ??? ?create table #tmpCompanyIDs
?? ??? ?(
?? ??? ??? ?CompanyID uniqueidentifier PRIMARY KEY,
?? ??? ??? ?TrackTime datetime
?? ??? ?)
?? ??? ?insert into #tmpCompanyIDs
?? ??? ?select t.CompanyID, max(TrackTime) TrackTime
?? ??? ?from CompanyTrack t
?? ??? ??? ?join CompanyExtension ce on ce.CompanyID = t.CompanyID
?? ??? ?where ce.OrganizationID = 1 and CE.AssignState = 2
?? ??? ?group by t.CompanyID
?? ??? ?select? comp.CompanyID
?? ??? ?from company as comp
?? ??? ?join #tmpCompanyIDs tc on tc.companyid=comp.companyid
?? ??? ?inner join SystemUser su on comp.SalesID=su.ID
?? ??? ?inner join Department dep on dep.DeptID=su.DeptID
?? ??? ?inner join UserSetting using on using.userID=su.ID
?? ??? ?where dep.departmentType=2 and using.AllocationFlag=0
?? ??? ?and? comp.DelStatus = 1 AND comp.[Status] = 1? AND comp.IsGroup = 1
?? ??? ?and tc.TrackTime<dateadd(day, 1 - @day, getdate())
?? ?end
end
-- exec Proc_GetCustomerIDByNoAwoke 1
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author:?? ??? ?ylem
-- Create date: 2010-04-15
-- Description:?? ?N天老隊銷售未跟進的客戶
-- =============================================
ALTER PROCEDURE [dbo].[Proc_GetCustomerIDByNoAwoke]
?? ?@orgId int --分公司ID
AS
BEGIN
??? declare @strDay varchar(32)
??? select @strDay = settingvalue from SystemSettings where OrganizationID=@orgId and SettingKey=25
?? ?if(@strDay is not null)
?? ?begin
?? ??? ?declare @day int
?? ??? ?set @day=cast(@strDay as int)
?? ??? ?create table #tmpCompanyIDs
?? ??? ?(
?? ??? ??? ?CompanyID uniqueidentifier PRIMARY KEY,
?? ??? ??? ?TrackTime datetime
?? ??? ?)
?? ??? ?insert into #tmpCompanyIDs
?? ??? ?select t.CompanyID, max(TrackTime) TrackTime
?? ??? ?from CompanyTrack t
?? ??? ??? ?join CompanyExtension ce on ce.CompanyID = t.CompanyID
?? ??? ?where ce.OrganizationID = 1 and CE.AssignState = 2
?? ??? ?group by t.CompanyID
?? ??? ?select? comp.CompanyID
?? ??? ?from company as comp
?? ??? ?join #tmpCompanyIDs tc on tc.companyid=comp.companyid
?? ??? ?inner join SystemUser su on comp.SalesID=su.ID
?? ??? ?inner join Department dep on dep.DeptID=su.DeptID
?? ??? ?inner join UserSetting using on using.userID=su.ID
?? ??? ?where dep.departmentType=2 and using.AllocationFlag=0
?? ??? ?and? comp.DelStatus = 1 AND comp.[Status] = 1? AND comp.IsGroup = 1
?? ??? ?and tc.TrackTime<dateadd(day, 1 - @day, getdate())
?? ?end
end
-- exec Proc_GetCustomerIDByNoAwoke 1
轉載于:https://www.cnblogs.com/ylemzhang/archive/2010/04/16/1713758.html
總結
- 上一篇: RHEL5下源码配置LAMP全记录
- 下一篇: 从表现现象查找电脑问题的根源