SQL Server Performance
  1. pandiarajan New Member

    I need query for Q1,Q2,Q3 data. Q is quarter.

    That is Q1=1 to 4
    Q2=4 to 8
    Q3=9 to 12

    I give above these parameters for this query.

    I select Q1 run this query. same run as Q2,Q3.

    (select d.valuedoc,
    (case when (d.el4='E9000') then 'Other Revenue' else '1' end ) as Line,
    from oas_dochead as h, oas_docline as d
    left outer join oas_grplist as g
    on d.el4=g.code and d.cmpcode=g.cmpcode and g.grpcode in ('21ONSITE', '21OFFSITE')
    where d.docnum=h.docnum
    and d.doccode=h.doccode
    and d.cmpcode=h.cmpcode
    and (h.yr between ?Year? - 3 and ?Year? and h.period between 1 and 4)
  2. ptsd21 New Member

    Hi,Are you explicitly storing the PERIOD in the database??If u are storing date in the database then you need not define the period/quarter explicitly. u can use the datepart function for Quarter. In where clause u can use the following statement.
    where  datepart(qq, date) = 1 --for Q1. similarly for 2 for Q2, etcHope this solves your problem.. if not share the DDL for all the tables??    

Share This Page