[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Help needed on a Inner Query.

Manny123 via SQLMonster.com

3/21/2007 12:40:00 PM

Hi there,

I would like to know how to accomplish the following;

The Outer query is retrieving Sales numbers from a date range and the Inner
Query should retrieve numbers from each date from the outer query od last
year.

@StartDate datetime,
@EndDate datetime

SELECT Sum(Sales) As Sales, SalesDate
FROM Sales

(SELECT Sum(Sales) AS SalesLY ??????

WHERE SalesDate Between @StartDate AND @EndDate

I was able to accomplish this but only for a single date but I can't find a
way to modify it to take a date range.

Thanks for your help.

Manny

--
Message posted via http://www.sqlm...

2 Answers

Roy Harvey

3/21/2007 12:59:00 PM

0

Try this and see if it gives you something to work with.

SELECT Sum(Sales) As Sales, SalesDate
FROM Sales
GROUP BY SalesDate

Roy Harvey
Beacon Falls, CT

On Wed, 21 Mar 2007 12:39:34 GMT, "Manny123" <u30518@uwe> wrote:

>Hi there,
>
>I would like to know how to accomplish the following;
>
>The Outer query is retrieving Sales numbers from a date range and the Inner
>Query should retrieve numbers from each date from the outer query od last
>year.
>
>@StartDate datetime,
>@EndDate datetime
>
>SELECT Sum(Sales) As Sales, SalesDate
>FROM Sales
>
> (SELECT Sum(Sales) AS SalesLY ??????
>
>WHERE SalesDate Between @StartDate AND @EndDate
>
>I was able to accomplish this but only for a single date but I can't find a
>way to modify it to take a date range.
>
>Thanks for your help.
>
>Manny

Uri Dimant

3/21/2007 1:01:00 PM

0

Manny123
Untested

SELECT <colums here> FROM Sales
WHERE Sales =(SELECT SUM(Sales) FROM Sales S1 WHERE S1.SalesDate BETWEEN
@StartDate AND @EndDate )


If it does not help ,please post DDL +sample data + an expected result














"Manny123" <u30518@uwe> wrote in message news:6f7d74cee56b0@uwe...
> Hi there,
>
> I would like to know how to accomplish the following;
>
> The Outer query is retrieving Sales numbers from a date range and the
> Inner
> Query should retrieve numbers from each date from the outer query od last
> year.
>
> @StartDate datetime,
> @EndDate datetime
>
> SELECT Sum(Sales) As Sales, SalesDate
> FROM Sales
>
> (SELECT Sum(Sales) AS SalesLY ??????
>
> WHERE SalesDate Between @StartDate AND @EndDate
>
> I was able to accomplish this but only for a single date but I can't find
> a
> way to modify it to take a date range.
>
> Thanks for your help.
>
> Manny
>
> --
> Message posted via http://www.sqlm...
>