Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case

Author  Topic 

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 2010-02-10 : 13:17:07
select

(case when MaterialsDate <> '' AND MaterialsDate <> ' ' AND MaterialsDate is not null
AND(countdt is null OR countdt ='' OR countdt =' ' OR countdt > CountDue) then callid end) as CountSLA
from
(
select cg.callid, dt.MaterialsDate, ag.groupname,sb.custid,
CONVERT(varchar(20), Dt.MaterialsDate + ' ' + Dt.MaterialsTime, 120) AS Materials,
CONVERT(varchar(20), Dt.CountDate + ' ' + Dt.CountTime, 120) AS Countdt,
CONVERT(varchar(20), Dt.Date3 + ' ' + Dt.Time3, 120) AS CountDue,
from calllog cg
join detail dt on cg.callid = dt.callid
join asgnmnt ag on ag.callid = dt.callid
join subset sb on sb.callid = cg.callid
where cg.calltype = 'Campaign' and cg.custtype = 'Company' and (Dt.ListName <> '')
AND (Dt.ListName IS NOT NULL)
)
T group by groupname


i want to create a case as:
before checking for countdt > CountDue
if the retrieved countdt is null then set countdt = getdate() then compare
otherwise compare with the already retrieved value not null countdt

How do i do that?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-10 : 13:20:28
quote:
Originally posted by nitsmooth

select

(case when MaterialsDate <> '' AND MaterialsDate <> ' ' AND MaterialsDate is not null
AND(countdt is null OR countdt ='' OR countdt =' ' OR COALESCE(countdt,GETDATE()) > CountDue) then callid end) as CountSLA
from
(
select cg.callid, dt.MaterialsDate, ag.groupname,sb.custid,
CONVERT(varchar(20), Dt.MaterialsDate + ' ' + Dt.MaterialsTime, 120) AS Materials,
CONVERT(varchar(20), Dt.CountDate + ' ' + Dt.CountTime, 120) AS Countdt,
CONVERT(varchar(20), Dt.Date3 + ' ' + Dt.Time3, 120) AS CountDue,
from calllog cg
join detail dt on cg.callid = dt.callid
join asgnmnt ag on ag.callid = dt.callid
join subset sb on sb.callid = cg.callid
where cg.calltype = 'Campaign' and cg.custtype = 'Company' and (Dt.ListName <> '')
AND (Dt.ListName IS NOT NULL)
)
T group by groupname


i want to create a case as:
before checking for countdt > CountDue
if the retrieved countdt is null then set countdt = getdate() then compare
otherwise compare with the already retrieved value not null countdt

How do i do that?



seems like what you need is small modification above

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 2010-02-11 : 05:10:48
Thanks for ur reply man
ur logic is correct
i modified my query
but now i have a problem that my countdt is not null only, they are ' ' also and i want the logic(COALESCE(countdt,GETDATE()) > CountDue) to work for those records also in which countdt is ' '
is that possible?

select
(case when MaterialsDate <> '' AND MaterialsDate <> ' ' AND MaterialsDate is not null
AND(COALESCE(countdt,GETDATE()) > CountDue) then callid end) as CountSLA
from
(
select cg.callid, dt.MaterialsDate, ag.groupname,sb.custid,
CONVERT(varchar(20), Dt.MaterialsDate + ' ' + Dt.MaterialsTime, 120) AS Materials,
CONVERT(varchar(20), Dt.CountDate + ' ' + Dt.CountTime, 120) AS Countdt,
CONVERT(varchar(20), Dt.Date3 + ' ' + Dt.Time3, 120) AS CountDue,
from calllog cg
join detail dt on cg.callid = dt.callid
join asgnmnt ag on ag.callid = dt.callid
join subset sb on sb.callid = cg.callid
where cg.calltype = 'Campaign' and cg.custtype = 'Company' and (Dt.ListName <> '')
AND (Dt.ListName IS NOT NULL)
)
T group by groupname

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 05:19:01
make it

COALESCE(NULLIF(countdt,''),GETDATE())

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nitsmooth
Yak Posting Veteran

68 Posts

Posted - 2010-02-12 : 02:08:31
Great ...this is it...thanks a lot man!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-12 : 02:10:58
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -