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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difficult sql query

Status
Not open for further replies.

mori0043

Programmer
Oct 28, 2004
23
0
0
CA
I have a complex query that returns a very large rowset containing five columns (I am simplifying it a bit here):
PrimaryKey, DATE1, DATE2, DATE3, DATE4

For each returned row I want to order the dates min to max and then based on each range of dates calculate a value from another query...

Is there a way to do this that is efficient?

SQL Server, Stored Proc...

Thanks in advance.
 
i'd recommend loading the dates into a tempory table, then working with the data. That's going to be the only way to order the coulumn data is to get it from the horizontial format that you have it in, into a vertical format.

PK, DateNumber, Date
1, 1, 1/1/2005
1, 2, 1/5/2005
...

A table that looks something like that should do the trick.

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Ok... It's soooo slow though since the tables are very large. Thanks, I guess that I will have to keep it this way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top