Re: getting sum of units sold in preceeding weeks

From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 05/11/04

  • Next message: Nikhil: "Re: getting sum of units sold in preceeding weeks"
    Date: Tue, 11 May 2004 11:32:37 +0530
    
    

      hi nikhil,

      pls post sample data, table structure to get correct results. However you
    can have query as follows, replace dt_column with the name of the date
    columns you have and sold_units with the "units sold" column of your table.

      select
      select sum(case when dt_column >= dateadd(dd, -7, {fn current_date()} )
    and dt_column <= getdate() then sold_units else 0 end) 'last week',
      sum(case when dt_column >= dateadd(dd, -14, {fn current_date()} ) and
    dt_column < dateadd(dd, -7, {fn current_date()} ) then sold_units else 0
    end) '2nd last week'
      /*
      ... so on, add sum(CASE... statements to above query till the required
    date.
      */
      from
      <table_name>

      --
      Vishal Parkar
      vgparkar@yahoo.co.in | vgparkar@hotmail.com


  • Next message: Nikhil: "Re: getting sum of units sold in preceeding weeks"

    Relevant Pages

    • RE: ORDER BY IIF(SoldUnits > 400, 0, 1), Description
      ... "Vishal Parkar" wrote: ... > Check if example shown in following query works for you. ... > select 'All about eve',810 union all ... >>> you post sample data and expected result set then it wd be easy to understand. ...
      (microsoft.public.sqlserver.datamining)
    • Re: flip the results
      ... Not enough info. if you are looking for sum of the columns you can have ... query as: ... union all ... Vishal Parkar ...
      (microsoft.public.sqlserver.programming)
    • Re: match those strings
      ... hi mikey, ... you can have query as follows. ... from left hand side of mfrpart column ... Vishal Parkar ...
      (microsoft.public.sqlserver.programming)
    • Re: match those strings
      ... > you can have query as follows. ... only 6 characters ... >from left hand side of mfrpart column ... > Vishal Parkar ...
      (microsoft.public.sqlserver.programming)
    • Re: BCP Command
      ... replace the query with yours put right servername / passwords etc. ... Vishal Parkar ...
      (microsoft.public.sqlserver.clients)