sql 查询以检查电子邮件中的重复项
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 查询以检查电子邮件中的重复项相关的知识,希望对你有一定的参考价值。
DECLARE @closedDate DATETIME = '2017-07-13 00:00:00.000'
DECLARE @roleLevel NVARCHAR(50) = 'L1'
--
DECLARE @period NVARCHAR(255)
DECLARE @quarter NVARCHAR(255)
--
DECLARE @workingDaysFromStartOfMonth INT = 0
DECLARE @workingDaysFromStartOfQuarter INT = 0
--
DECLARE @tblDayCCC TABLE (
[TowerLead] NVARCHAR(255)
,[TowerLeadEmail] NVARCHAR(255)
,[ManagerName] NVARCHAR(255)
,[ManagerEmail] NVARCHAR(255)
,[EngineerName] NVARCHAR(255)
,[EngineerEmail] NVARCHAR(255)
,SecondaryRole NVARCHAR(255)
,[WorkScope] NVARCHAR(255)
,[ClosedDate] DATETIME
,[ClosedCaseCount] FLOAT
)
DECLARE @tblMonthCCC TABLE (
[TowerLead] NVARCHAR(255)
,[TowerLeadEmail] NVARCHAR(255)
,[ManagerName] NVARCHAR(255)
,[ManagerEmail] NVARCHAR(255)
,[EngineerName] NVARCHAR(255)
,[EngineerEmail] NVARCHAR(255)
,SecondaryRole NVARCHAR(255)
,[WorkScope] NVARCHAR(255)
,[Month] NVARCHAR(255)
,[ClosedCaseCount] FLOAT
)
DECLARE @tblQuarterCCC TABLE (
[TowerLead] NVARCHAR(255)
,[TowerLeadEmail] NVARCHAR(255)
,[ManagerName] NVARCHAR(255)
,[ManagerEmail] NVARCHAR(255)
,[EngineerName] NVARCHAR(255)
,[EngineerEmail] NVARCHAR(255)
,SecondaryRole NVARCHAR(255)
,[WorkScope] NVARCHAR(255)
,[FiscalQuarter] NVARCHAR(255)
,[ClosedCaseCount] FLOAT
)
SELECT TOP 1 @period = vccd.Period
FROM dbo.vw_ClosedCaseDetailed vccd
WHERE vccd.[Closed Date] = @closedDate
SELECT TOP 1 @quarter = vccd.[FiscalQuarter]
FROM dbo.vw_ClosedCaseDetailed vccd
WHERE vccd.[Closed Date] = @closedDate
------------------------Day Closed Case Count----------------
INSERT INTO @tblDayCCC (
[TowerLead]
,[TowerLeadEmail]
,[ManagerName]
,ManagerEmail
,[EngineerName]
,[EngineerEmail]
,SecondaryRole
,[WorkScope]
,[ClosedDate]
,ClosedCaseCount
)
SELECT vccd.[Tower Lead]
,vccd.[TowerLeadEmail]
,vccd.[Manager Name]
,vccd.[Manager Email Address]
,vccd.[Engineer Name]
,vccd.[Engineer Email Address]
,vccd.[Secondary Role]
,vccd.[Work Scope]
,vccd.[Closed Date]
,COUNT(DISTINCT vccd.CaseNumber)
FROM dbo.vw_ClosedCaseDetailed vccd
WHERE vccd.[Closed Date] = @closedDate
AND vccd.RoleLevel = @roleLevel
GROUP BY vccd.[Tower Lead]
,vccd.[TowerLeadEmail]
,vccd.[Manager Name]
,vccd.[Manager Email Address]
,vccd.[Engineer Name]
,vccd.[Engineer Email Address]
,vccd.[Secondary Role]
,vccd.[Work Scope]
,vccd.[Closed Date]
------------------------Month Closed Case Count----------------
INSERT INTO @tblMonthCCC (
[TowerLead]
,[TowerLeadEmail]
,[ManagerName]
,ManagerEmail
,[EngineerName]
,[EngineerEmail]
,SecondaryRole
,[WorkScope]
,[Month]
,ClosedCaseCount
)
SELECT vccd.[Tower Lead]
,vccd.[TowerLeadEmail]
,vccd.[Manager Name]
,vccd.[Manager Email Address]
,vccd.[Engineer Name]
,vccd.[Engineer Email Address]
,vccd.[Secondary Role]
,vccd.[Work Scope]
,vccd.Period
,COUNT(DISTINCT vccd.CaseNumber)
FROM dbo.vw_ClosedCaseDetailed vccd
WHERE vccd.Period = @period
AND vccd.RoleLevel = @roleLevel
GROUP BY vccd.[Tower Lead]
,vccd.[TowerLeadEmail]
,vccd.[Manager Name]
,vccd.[Manager Email Address]
,vccd.[Engineer Name]
,vccd.[Engineer Email Address]
,vccd.[Secondary Role]
,vccd.[Work Scope]
,vccd.Period
------------------------Quarter Closed Case Count----------------
INSERT INTO @tblQuarterCCC (
[TowerLead]
,[TowerLeadEmail]
,[ManagerName]
,ManagerEmail
,[EngineerName]
,[EngineerEmail]
,SecondaryRole
,[WorkScope]
,FiscalQuarter
,ClosedCaseCount
)
SELECT vccd.[Tower Lead]
,vccd.[TowerLeadEmail]
,vccd.[Manager Name]
,vccd.[Manager Email Address]
,vccd.[Engineer Name]
,vccd.[Engineer Email Address]
,vccd.[Secondary Role]
,vccd.[Work Scope]
,vccd.FiscalQuarter
,COUNT(DISTINCT vccd.CaseNumber)
FROM dbo.vw_ClosedCaseDetailed vccd
WHERE vccd.FiscalQuarter = @quarter
AND vccd.RoleLevel = @roleLevel
GROUP BY vccd.[Tower Lead]
,vccd.[TowerLeadEmail]
,vccd.[Manager Name]
,vccd.[Manager Email Address]
,vccd.[Engineer Name]
,vccd.[Engineer Email Address]
,vccd.[Secondary Role]
,vccd.[Work Scope]
,vccd.FiscalQuarter
SELECT TOP 1 @workingDaysFromStartOfMonth = Result
FROM [dbo].[UDF_GetWorkingDayStartMonthToDateExcludingWeekends](@closedDate)
SELECT TOP 1 @workingDaysFromStartOfQuarter = Result
FROM [dbo].[UDF_GetWorkingDayStartQuarterToDateExcludingWeekends](@closedDate)
DECLARE @engName NVARCHAR(255) = 'Priyanka V'
DECLARE @mgrName NVARCHAR(255) = 'Bhakar'
SELECT *
FROM @tblQuarterCCC tqc
WHERE tqc.EngineerName LIKE '%' + @engName + '%'
AND tqc.ManagerName LIKE '%' + @mgrName + '%'
SELECT *
FROM @tblMonthCCC tmc
WHERE tmc.EngineerName LIKE '%' + @engName + '%'
AND tmc.ManagerName LIKE '%' + @mgrName + '%'
SELECT *
FROM @tblDayCCC tdc
WHERE tdc.EngineerName LIKE '%' + @engName + '%'
AND tdc.ManagerName LIKE '%' + @mgrName + '%'
SELECT tqc.TowerLead
,tqc.TowerLeadEmail
,tqc.[ManagerName]
,tqc.ManagerEmail
,tqc.[EngineerName]
,tqc.EngineerEmail
,tqc.[WorkScope]
,tqc.SecondaryRole
,tdc.ClosedCaseCount AS DayCount
,tmc.ClosedCaseCount AS MonthCount
,tqc.ClosedCaseCount AS QuaterCount
,CASE
WHEN @workingDaysFromStartOfMonth > 0
THEN ROUND(tmc.ClosedCaseCount / @workingDaysFromStartOfMonth, 2)
ELSE 0
END AS MPI
,CASE
WHEN @workingDaysFromStartOfQuarter > 0
THEN ROUND(tqc.ClosedCaseCount / @workingDaysFromStartOfQuarter, 2)
ELSE 0
END AS QPI
FROM @tblQuarterCCC tqc
FULL JOIN @tblMonthCCC tmc ON tqc.TowerLead = tmc.TowerLead
AND tqc.TowerLeadEmail = tmc.TowerLeadEmail
AND tqc.ManagerName = tmc.ManagerName
AND tqc.ManagerEmail = tmc.ManagerEmail
AND tqc.EngineerName = tmc.EngineerName
AND tqc.EngineerEmail = tmc.EngineerEmail
AND tqc.SecondaryRole = tmc.SecondaryRole
AND tqc.WorkScope = tmc.WorkScope
FULL JOIN @tblDayCCC tdc ON tmc.TowerLead = tdc.TowerLead
AND tmc.TowerLeadEmail = tdc.TowerLeadEmail
AND tmc.ManagerName = tdc.ManagerName
AND tmc.ManagerEmail = tdc.ManagerEmail
AND tmc.EngineerName = tdc.EngineerName
AND tmc.EngineerEmail = tdc.EngineerEmail
AND tmc.SecondaryRole = tdc.SecondaryRole
AND tmc.WorkScope = tdc.WorkScope
WHERE tqc.EngineerName LIKE '%' + @engName + '%'
AND tqc.ManagerName LIKE '%' + @mgrName + '%'
ORDER BY tqc.[ManagerName] ASC
,tqc.EngineerName ASC
以上是关于sql 查询以检查电子邮件中的重复项的主要内容,如果未能解决你的问题,请参考以下文章