SQL Query Issue

  • I have a query where I am pulling data on daily basis for a specific start and end dates. For some of the days ex Sunday we have no row for that day in the database but user want to display the date and count as 0. I am not sure how can we display the date when no row/record for that day exist in database. can anyone please give me idea.

  • ISNULL(YourTable.DateField,GETDATE() ) DateField, ISNULL(CountField, 0) CountField

    Note that that code displays the exact date with the time portion, you could also trim off the time portion to show just the date. If you want a more fitting answer for your scenario, post the query.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • This common requirement usually can be resolved using a calendar table.

    Search this site for "calendar table" and you'll find a variety of solutions and discussions related to it.

    If you have more detailed requirements, please provide more detailed information.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply