T-SQL Sum IIf query -


    select t1.detail_date clmdate     ,t1.detail_agentid clmpid     ,t3.hodcode clmhod     ,t1.detail_callshandled clmibconnects     ,t1.detail_talktime clmibtalk     ,t1.detail_wraptime clmibwrap     ,t1.detail_holdtime clmibhold     ,t1.detail_handletime clmibtotal     ,sum(iif([fldcallroute.value] = [inbound],0)) clmibconnects --  ,sum(iif([fldcallroute] = "inbound", [clmtalk], 0)) ibtalk --  ,sum(iif([fldcallroute] = "inbound", [clmwrap], 0)) ibwrap --  ,sum(iif([fldcallroute] = "inbound", [clmtalk] + [clmwrap] + [clmhold], 0)) ibtotal     ,sum(0) clmobsignedon     ,sum(0) preview     ,sum(0) obtalk     ,sum(0) obupdate     ,sum(0) obwork     ,sum(0) obconnects --  ,sum(iif([fldcallroute] = "inbound", [clmhold], 0)) ibhold --  ,sum(iif([fldcallroute] = "outbound", [clmhold], 0)) obhold} 

i not getting sum(iif.. part of queries more specifically: ,sum(iif([fldcallroute] = "inbound", [clmibconnects], 0)) clmibconnects

it shows invalid column name 'inbound' invalid column name 'clmibconnects'?

fldcallroute column in table t2 has entries inbound i'm not sure why saying column name inbound?

you need single quotes string constants:

sum(iif([fldcallroute] = 'inbound', [clmtalk], 0)) ibtalk, 

i have preference case on iif(). case ansi standard , available in databases:

sum(case when fldcallroute = 'inbound' clmtalk else 0 end) ibtalk, 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -