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.
| 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 CountSLAfrom(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 groupnamei want to create a case as: before checking for countdt > CountDueif the retrieved countdt is null then set countdt = getdate() then compareotherwise compare with the already retrieved value not null countdtHow 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 CountSLAfrom(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 groupnamei want to create a case as: before checking for countdt > CountDueif the retrieved countdt is null then set countdt = getdate() then compareotherwise compare with the already retrieved value not null countdtHow do i do that?
seems like what you need is small modification above------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2010-02-11 : 05:10:48
|
| Thanks for ur reply manur 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 CountSLAfrom(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 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-11 : 05:19:01
|
| make itCOALESCE(NULLIF(countdt,''),GETDATE())------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2010-02-12 : 02:08:31
|
| Great ...this is it...thanks a lot man! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-12 : 02:10:58
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|