I am creating a front end with VB6 and my database is Sybase. Using DSN I have created some small exe\'s to populate reports in grid. It was working fine.
However if I u
You cannot use when user_id <> Null
. You must use user_id Is Null
or user_id Is Not Null
. Anything = or <> to Null results in Unknown which is treated as false for the Case expression.
Just so you know the count(seqnum) as Answered is not the correct definition for Aspect UIP inbound calls answered. If you check the field labeled SwitchDispId it could have a 1 or 2 in it which would equate to an abandon call. Hence not a answered call. I do see you are using user_id not null to get answered calls but I just wanted to make you aware of that.
Also you can join the acdcalldetail table to the service table to get names that look more like what the business is used to seeing like this:
SELECT
Service_c
,SUM(CASE WHEN acd.SwitchDispID IN (1,2) THEN 1 ELSE 0 END as Abandons
,SUM(CASE WHEN acd.user_id is not null THEN 1 ELSE 0 END as Answered
FROM acdcalldetail acd
JOIN service s
ON s.service_id = acd.service_id
AND s.sourceid = acd.sourceid
WHERE acd.CallStartDt between '20170501' AND '20170530'
AND s.Service_id NOT IN (37,39,47,51,57,58,96,215,374,375)
GROUP BY
s.Service_c
"select datepart (hh, callstartdt) as Hour, " _
& " count(seqnum) as Anaswered," _
& " sum(case when user_id <> NULL then 1 else 0 end) as answered_calls ," _
& " sum(case when user_id <> NULL and datediff (ss, callstartdt, QueueEndDt) <= 20 then 1 else 0 end) , " _
& " sum(case when user_id = NULL then 1 else 0 end), " _
& " sum(case when user_id <> NULL and datediff (ss, callstartdt, QueueEndDt) <= 20 then 1 else 0 end) / count(seqnum), " _
& " sum(Case when user_id <> NULL then 1 else 0 end ) / count(seqnum) from acdcalldetail " _
& " where callstartdt between '" & fromDt & "' and '" & toDt & "' " _
& " and service_id not in (37,39,47,51,57,58,96,215,374,375) " _
& " group by datepart (hh, callstartdt) " _
& " order by datepart (hh, callstartdt)"
Nicholas, I agree with you in that comparisons against null should always be false, however I tried the following code on an ASE 15.0.3 server and got a surprising result
declare @xx int
select @xx = null
select @xx
select 1 where null = @xx
It return 1 for the second select which I was not expecting..
General Rule: any operation involving NULL yields NULL. All comparisons involving NULL fail, regardless of whether or not the test is positive ('==') or negative ('<>'). The sole exception being explicit tests for nullity via IS [NOT] NULL or use of COALESCE()/ISNULL().
I guess for sysbase it is the same as for sql-server.
There is a setting to switch between (old?) sybase default
set ansi_nulls off
select case when null = null then 1 else 0 end
-- returns 1
and ansi behaviour.
set ansi_nulls on
select case when null = null then 1 else 0 end
-- returns 0
Today the question is hardly which setting is more elegant, but with which setting causes more trouble.