|
 |
asp_databases thread: Need some help with SQL statement
Message #1 by "Thomas V. Nielsen" <t.v.nielsen@s...> on Mon, 17 Apr 2000 14:0:8
|
|
Hi There,
My problem is, that I want to display the first date of some record in a
database, the trick lies in, that there is actually two tables where the
information comes from (Not my idea!)
So my simple query goes like this:
SELECT MIN(dateonline) FROM theTable
UNION
SELECT MIN(dateonline) FROM theTable_archive
The problem is now, that I have to record set with one value, now I only
have to figure out, which one of the is the lowest
Perhaps I should mention that it is NOT a date field but a varChar field
I'm
retrieving the date, which is stored in the format YYYYMMDD
Kind regards
/Thomas
Message #2 by "Jim Maddocks" <james.maddocks@t...> on Wed, 26 Apr 2000 13:8:58
|
|
Thomas,
Not knowing the full context of what you are doing with the records,
or what you want to do with them when they are returned,
here is one idea ...
add an order by statement to the end of your query so that you know
the first record you encounter will be the earliest.
Also, I'm not sure your current statement would work correctly unless you
use the covert(datetime,dateonline) function (otherwise it is returning the
min varchar value of that field):
SELECT MIN(convert(datetime,dateonline)) FROM theTable
where whereclause
UNION
SELECT MIN(convert(datetime,dateonline) FROM theTable_archive
where whereclause
order by 1
also i'm assuming there is some whereclause that furthur limits the
scope of the records returned
Hope this helps.
Jim Maddocks
|
|
 |