Solved

Count Number of rows per day in Sybase database

Posted on 2004-09-08
4
395 Views
Last Modified: 2008-02-26
I have a very big table in my sybase database.
I need to count the number of rows for the last 7 days.

Could you please help me with a simple sql script.
This query should check the last date and calculate the number of rows for the 7 previous date.

Thanks a lot
Abdel
0
Comment
Question by:abidar
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 250 total points
ID: 12012244
SELECT Count(*)
FROM YourTableName
WHERE YourDateColumn >= DateAdd(d,-7,GetDate())
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12012264
GetDate() is the T-SQL function to return the current system time. DateAdd is the function to add or subtract from datetime values. So the query above subtracts 7 days from the current date, then checks your date column to see if it's later than that. Anything counted will be in the last 7 days. With a lot of records, it will help to create an index on the date column like this:

CREATE INDEX index_on_MyDateColumn ON MyTableName(MyDateColumn)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
understanding output of mysql version 2 61
compre toata in where clue oracle 4 58
#deleted rowsc access 2010 backend 4 55
compare between entities in entity framework 8 73
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question