SELECT Question

  • 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.

  • Sounds like a homework question. You'll need to look up the left join clause.

    Tom

  • I think you would be better off looking at GROUP BY and ALL in BOL to find your answer.

  • GROUP BY ALL is being depreciated.  The left join from a calendar table is the safest solution.

  • ok,

    sounds like a good idea. but is there another choice if i don't really have a calender table to work with ?

    benedito.

  • hello again,

    what i need is to list all days between two given dates in a single SQL command.

    thanks,

    benedito.

  • Answer for yourself:

    Where those days are stored?

    _____________
    Code for TallyGenerator

  • 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.

  • 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.

  • 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.

  • You did not answer the question.

    _____________
    Code for TallyGenerator

  • 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

  • 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.

  • that's ok, guys,

    i'm solving the problem with a SP.

    thanks,

    levogiro.

  • 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