Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting transactions for a set date

Status
Not open for further replies.

SonOfZeus

Programmer
Mar 6, 2002
53
CA
I've developed a stored procedure to retrieve the travel logs for vehicles on a specified date. The issue I'm hitting now is I want all vehicles, even if they didn't travel on that date to be returned, with the travel info simply blank. i.e.

Vehicle1 June 13 25Kilometers
Vehicle2 June 13 10Kilometers
Vehicle3
Vehicle4 June 13 10Kilometers

Other records may or may not exist for a vehicle on other days, thus the = june 13 or travellog.date isnull won't work.

Any ideas
 
Assuming you have two tables which look something like this, you can do something like this:

a.vid
a.vdescription

b.vid
b.traveldate
b.milestraveled

select a.vid,
a.vdescription,
b.traveldate,
sum(case when b.milestraveld is null then 0 else
b.milestraveled end) as totaldistance
from a left outer join b on a.vid = b.vid
where b.traveldate between @StartDate and @EndDate
group by b.traveldate, a.vdescription, a.vid
order by b.traveldate, a.vdescription, a.vid
 
How about creating a temp table with the fields you need. Then populate it with the unique vehicle names and then update it with the info for a specific date (other vehicles would stay null)and finally display the temp table results?
 
A temp table would work within the stored procedure. I have to refresh myself on temp tables as two people may be calling this procedure with different dates. Thanks
 
Hi,

Maybe u can create a local temporary tables which are visible only in the current session. A create statement with a single # will do it some thing like this..

CREATE TABLE #temptale (fld1 INT).


But i think that it might be possible to get the data with as u want from a SQL. if u could put some sample data from tables and what output u r looking for. May be we can try to get the data with a SQL

Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top