Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL SERVER - count from one day to another

Status
Not open for further replies.

fullmoon2

Technical User
Aug 14, 2005
20
Hi

I have a little problem I hope someone can help me solve:

I'm going to count from one date to another, like from 2011-01-01 to today.

And I'm going to put it into a view:

CREATE VIEW VWtotalsale
AS
SELECT sales.title_id, sales.qty, titles.price, sales.ord_date
FROM sales INNER JOIN titles ON sales.title_id = titles.title_id

SELECT SUM(qty * price) AS totalsale FROM VWtotalsale
(finds the totalsale for the whole table)

and add the totalsale from 2011-01-01 to today..

Anyone that have an idea?

Thanks in advance :)
 
This shouldn't be difficult... you don't have to count from one date to another.... just use a where....

Something along the lines of:

SELECT SUM(qty * price) AS TotalSale FROM VWtotalsale WHERE (SalesDate >= '2011-01-01' AND SalesDate <= GetDate())

No point in looping where you don't have to....



Just my 2¢

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top