count the rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RISHA
    New Member
    • Jul 2008
    • 2

    count the rows

    can someone please help me.i wanted to count the rows of a table for today,30 days back,90 days back and 180 days back.can someone please help me to write a code for this in sql.thanks
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    will this work?

    Code:
    select 
    30days = 
    sum(case when abs(datediff(dd,getdate(),yourdatefield)) = 30 then 1 else 0 end),
    60days = 
    sum(case when abs(datediff(dd,getdate(),yourdatefield)) = 60 then 1 else 0 end)
    90days = 
    sum(case when abs(datediff(dd,getdate(),yourdatefield)) = 90 then 1 else 0 end)
    from yourtable
    -- CK

    Comment

    • RISHA
      New Member
      • Jul 2008
      • 2

      #3
      i have to i have data in my table.i need to count the open issues for today ,30 days back,90 days back,180 days back.

      i wrote a stored procedure
      select projectname,cou nt('x') as "today's count",(select count('x') from table1 where(datediff( day,date_submit ted.getdate())> =30) group by projectname)as "30 days back count",(select. ......).

      when i write stored procedure like this i get a error as subquery returns more than 1 row.

      so i tried to write the subquery in the from clause.like

      select projectname,cou nt('x) as "todays count"
      from(select count('x') where datediff(day,da te_submitted,ge tdate())>=30) as "30 days bck count
      from table1
      groupby projectname)
      here too i get the error as incorrect keyword near from.i don't know how to fix it.can you please help me.thanks












      --

      Comment

      Working...