Solved

Count Number of rows per day in Sybase database

Posted on 2004-09-08
4
394 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
Quick and High level SQL Server 2012 Performance check 8 51
report returning null 21 81
VBA MS Word "Table of Contents" extractor` 4 25
constraint check 2 19
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now