我有一个在MS SQL Server 8中成功运行的查询,但在尝试在Report Builder中执行时,我得到“已添加相同密钥的项目”错误。任何帮助将非常感激。
这是我的问题:
DECLARE @firstDate DATETIME = ''
DECLARE @lastDate DATETIME = ''
DECLARE @inqtype VARCHAR(1000) = ''
SET @firstDate = '12/1/2016'
SET @lastDate = '12/3/2016'
SELECT @firstDate, @lastDate, DATEDIFF(dd, @firstDate, @lastDate)
SELECT @firstDate, @lastDate, DATEDIFF(HH, @firstDate, @lastDate)
SELECT @firstDate, @lastDate, DATEDIFF(HH, CONVERT(time, @firstDate), CONVERT(time, @lastDate))
SELECT @firstDate, @lastDate, DATEDIFF(MI, @firstDate, @lastDate)
SELECT DATEPART(MI, @lastDate), DATEPART(MI, @firstDate)
SELECT
*
,CASE
WHEN minutes <= 1440
THEN 'Yes'
WHEN minutes >= 1440
THEN 'No'
END AS Compliance
FROM
(
select Distinct
INQ.FundCode,
INQ.County,
INQ.InquiryID,
CONT.FIRSTNAME,
CONT.LASTNAME,
CONT.LASTNAME + ', ' + CONT.FIRSTNAME AS Worker,
supercontact.LASTNAME + ', ' + supercontact.FIRSTNAME as Supervisor,
INQ.Status,
INQ.Immediacy,
INQ.DateReceived,
INQ.InquirySource,
INQ.InqType,
INQ.EntryDate,
INQ.EntryTime,
INQ.ScreeningDate,
INQ.ScreeningTime,
(DATEDIFF(DAY,INQ.EntryDate,INQ.ScreeningDate)) as days,
(DATEDIFF(hour,INQ.EntryDate,INQ.ScreeningDate)) as hours,
(DATEDIFF(Minute,INQ.EntryTime,INQ.ScreeningTime)) as minutes
from INQUIRY INQ
left join INQUIRYHistory intakeworker ON intakeworker.RECEIVEDBY = inq.RECEIVEDBY
left join HISPeople people ON people.MemberId = intakeworker.RECEIVEDBY
left join HISPeopleName intakeworkername ON people.PeopleId = intakeworkername.PeopleID
left join WORKERS work ON work.memberId = inq.RECEIVEDBY
left join CONTACT cont ON cont.ContactId= work.ContactId
left join HISInquiryLink inql ON inql.Datetimestamp=inq.DATETIMESTAMP
left join supervisors super WITH (NOLOCK) on work.MemberID = super.MEMBERID
and super.active = 1 and super.primarysuper = 1 and super.StartDate <= GETDATE() and (super.EndDate > GETDATE()
OR super.EndDate is NULL)
left join workers superworker WITH (NOLOCK) on super.supervisor = superworker.memberid
left join users su WITH (NOLOCK) on superworker.memberid =su.memberid
left join contact supercontact WITH (NOLOCK) on superworker.contactid = supercontact.contactid
where
INQ.EntryTime BETWEEN @firstDate AND @lastDate
AND INQ.InqType IN (@inqtype)
--AND INC.FundCode = 'ALL'
--AND work.active = 1
)Temp
ORDER by Temp.EntryTime