January 3, 2007 at 11:20 am
hi,
i have to select the total products sold by day in a period of time, but i have to present all days in the period includind those where no products were sold.
thanks,
benedito.
January 3, 2007 at 2:24 pm
Sounds like a homework question. You'll need to look up the left join clause.
Tom
January 3, 2007 at 3:46 pm
I think you would be better off looking at GROUP BY and ALL in BOL to find your answer.
January 3, 2007 at 5:28 pm
GROUP BY ALL is being depreciated. The left join from a calendar table is the safest solution.
January 4, 2007 at 4:21 am
ok,
sounds like a good idea. but is there another choice if i don't really have a calender table to work with ?
benedito.
January 4, 2007 at 4:51 am
hello again,
what i need is to list all days between two given dates in a single SQL command.
thanks,
benedito.
January 4, 2007 at 5:20 am
January 4, 2007 at 5:30 am
sergiy,
there's no table storing the dates. i want to pass 2 dates to a SQL command and calculate them in this command.
benedito.
January 4, 2007 at 5:41 am
There are a few ways of doing this. One would be to create a table with all the days in it and then link from there. Another is to do the same, but use a temp table. I have also seen this done in a single select statement using complex full outer joins, but that was not very readable.
January 4, 2007 at 5:42 am
If you don't have a clendar table to work with, create a temp table for dates and populate a row for every date in the range. You can then left join into this.
January 4, 2007 at 5:54 am
You did not answer the question.
_____________
Code for TallyGenerator
January 4, 2007 at 6:43 am
In order to display something you need to retrieve it from somewhere.
Where those not mentioned days suppose to be taken from?
_____________
Code for TallyGenerator
January 4, 2007 at 10:41 am
Be more specific, please! What do you mean by 'calculate them'?
On second thought, I haven't got a clue as to what your problem is.
January 4, 2007 at 12:25 pm
that's ok, guys,
i'm solving the problem with a SP.
thanks,
levogiro.
January 4, 2007 at 1:07 pm
Great! And when you have finished writing the SP, publish a copy of it on this thread. Maybe then we'll finally understand the problem you are trying to solve.
What is amazing is that your initial post presents a problem quite clearly. But there are so many uncertainties and 'if this' and 'if that' and 'what do you mean by this' and 'oh yes, I forgot about that...'.
It's all about specifications and presenting a problem clearly. When it's all clear, writing the SP is the easy part.
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply