AGeek AGeek - 5 months ago 27
SQL Question

SQL Query for range of dates

Lets frame the question again---

table1{date, bID, sName, fID}

This is the table and the data stored in the table is also specified...

Now the query that i want is that:-

Depending of fId (lets say, P1 is selected) it should display the data from table say from 11/05-17/05 (no date should be missed). The data retrieved is as follows:-


The data retrieved for a particular fID(say P1) is displayed.. Explaning the result...

1) it displayed all data from 11/05-17/05 where fId is P1, if there is no date in the database, then also it should display null value for that date (i.e.14/05 date was not there in database, but still it displayed with a null value)..

2) if fId for that particular date is not P1, then also it store a null value in result set..

Atlast the data is retrieved in result set,, and processed further..

So i want to write the query for this problemm,, is it possible..

Answer Source

No code here, just my thoughts.

You need to create a temporary table with dates ranging from your begin date to an end date, inclusive. And then left join table1 with that temporary table on date column plus add where fID = ?.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download