I have a script below that I need to convert to a T-SQL. Anybody knows how to convert it? Thanks.
declare
@Date varchar(10), @programid int
set @Date = '03/05/2006'
set @ProgramId = 31
--Select @Date = convert(char(10), getdate()-1,101)
select isnull(a.[first name],agdet.[agent id]) agent, *
from
(select [agent id], substring(transfernumber, 1,11) transfernumber, tr.[description] [description], convert(char(8), [start datetime],8) [transfertime], [talk time]
from OPT.DBO.Interactions I
INNER JOIN OPT.DBO.[Telephone Contacts] T
ON I.[Interaction ID] = T.[Interaction Id]
inner join [HRS].[dbo].[transfernumbers] TR
on TransferNumber = TR.DNIS
where [start datetime] between @Date + ' 00:00:00' and @Date + ' 23:59:59'
and [client code] in (select clientid from OPT.DBO.edwrptmapping where programid = @programid)
and [program code] in(select edwprogramid from OPT.DBO.edwrptmapping where programid = @programid)
and I.[interaction type] = 'T' and [final status] = 'C'
and [Center Code] = 'G' and [agent id] is not null and TR.Show = 1 and TR.CIC = 'CR'
) agdet
right join
(select [agent id], sum(case when tr.dnis is not null then 1 else 0 end) transfers, count(*) as calls
from OPT.DBO.Interactions I
INNER JOIN OPT.DBO.[Telephone Contacts] T
ON I.[Interaction ID] = T.[Interaction Id]
left join [HRS].[dbo].[transfernumbers] TR
on TransferNumber = TR.DNIS and TR.Show = 1 and TR.CIC = 'CR'
where [start datetime] between @Date + ' 00:00:00' and @Date + ' 23:59:59'
and [client code] in (select clientid from OPT.DBO.edwrptmapping where programid = @programid)
and [program code] in(select edwprogramid from OPT.DBO.edwrptmapping where programid = @programid)
and I.[interaction type] = 'T' and [final status] = 'C'
and [Center Code] = 'G' and [agent id] is not null
group by [agent id]) agtot
on agdet.[agent id] = agtot.[agent id]
left join OPT.DBO.agents a on agtot.[agent id] = a.[agent id]
order by isnull( a.[first name],agdet.[agent id]), [transfertime]
declare
@Date varchar(10), @programid int
set @Date = '03/05/2006'
set @ProgramId = 31
--Select @Date = convert(char(10), getdate()-1,101)
select isnull(a.[first name],agdet.[agent id]) agent, *
from
(select [agent id], substring(transfernumber, 1,11) transfernumber, tr.[description] [description], convert(char(8), [start datetime],8) [transfertime], [talk time]
from OPT.DBO.Interactions I
INNER JOIN OPT.DBO.[Telephone Contacts] T
ON I.[Interaction ID] = T.[Interaction Id]
inner join [HRS].[dbo].[transfernumbers] TR
on TransferNumber = TR.DNIS
where [start datetime] between @Date + ' 00:00:00' and @Date + ' 23:59:59'
and [client code] in (select clientid from OPT.DBO.edwrptmapping where programid = @programid)
and [program code] in(select edwprogramid from OPT.DBO.edwrptmapping where programid = @programid)
and I.[interaction type] = 'T' and [final status] = 'C'
and [Center Code] = 'G' and [agent id] is not null and TR.Show = 1 and TR.CIC = 'CR'
) agdet
right join
(select [agent id], sum(case when tr.dnis is not null then 1 else 0 end) transfers, count(*) as calls
from OPT.DBO.Interactions I
INNER JOIN OPT.DBO.[Telephone Contacts] T
ON I.[Interaction ID] = T.[Interaction Id]
left join [HRS].[dbo].[transfernumbers] TR
on TransferNumber = TR.DNIS and TR.Show = 1 and TR.CIC = 'CR'
where [start datetime] between @Date + ' 00:00:00' and @Date + ' 23:59:59'
and [client code] in (select clientid from OPT.DBO.edwrptmapping where programid = @programid)
and [program code] in(select edwprogramid from OPT.DBO.edwrptmapping where programid = @programid)
and I.[interaction type] = 'T' and [final status] = 'C'
and [Center Code] = 'G' and [agent id] is not null
group by [agent id]) agtot
on agdet.[agent id] = agtot.[agent id]
left join OPT.DBO.agents a on agtot.[agent id] = a.[agent id]
order by isnull( a.[first name],agdet.[agent id]), [transfertime]