sql - Query to add few fields in subquery -


select      t0.docdate [grpo posting date],     t0.docnum [grpo num]     ,t0.cardname  opdn t0       year(t0.docdate) ='2016'     , (dateadd(day, 1, t0.docdate) in (         select odln.docduedate          odln          year(docduedate) = '2016'     ) 

this query works fine.but need fetch other information. don't know how add existing query.

for e.g. apart grpo posting date, grpo num, cardname, need fetch odln.docnum, odln.docduedate have using in sub query.

please me amend query or new query requirements.

what want inner join odln:

select     t0.docdate [grpo posting date],     t0.docnum [grpo num],     t0.cardname,     t1.docnum,     t1.docduedate opdn t0 inner join odln t1     on dateadd(day, 1, t0.docdate) = t1.docduedate     t0.docdate >= '20160101' , t0.docdate < '20170101'     , t1.docduedate >= '20160101' , t1.docduedate < '20170101' 

note:

  • avoid using functions on columns in where clause makes query non-sargable. in case, can write

    year(t0.docdate) = '2016'` 

    as

    t0.docdate >= '20160101' , t0.docdate < '20170101' 

Comments

Popular posts from this blog

javascript - Hide toolbar of pdf file opened inside iframe using firefox -

Ansible - ERROR! the field 'hosts' is required but was not set -

Copy range with conditional formatting -