Question : How do compare two fields and based on a True comparison input into another field?

Ok, I have a table that has DeviceName, OutageType, OutageDate,DownDate,TotalDown.

ColA has multiple entries based on when an outaged happened (whether outage was down or up).
ColB has the type of outage for the specified device in ColA (again Up or Down)
ColC is the date the outage (in ColB) occurred
ColD is the date the device (in ColA) went down
ColE is the total time (in decimal format) that the device was down (this is a precalculated field inserted from another script) but only attached to fields/rows which devicetype='up'

The table looks like:
abcd-s-2-01,Down,<outagedate>,Null,Null
abcd-s-2-01,Up,<outagedate>,<downdate>,<totaltime>
abcd-s-2-01,Down,<outagedate>,Null,Null
abcd-s-2-01,Up,<outagedate>,<downdate>.<totaltime>

Basically an outage type of Down only contains the device name, the type of outage and when that outage occured.  An outage type of Up contains the name, type, date of outage, date device went down, and the total time it was down

Here is what I need.  I need to create a new table that contains:
DeviceName
DeviceType
DownDate
UpDate (this is the date in which the devicetype='Up' for the device listed above in ColA)
TotalDown

The above needs to be for only those devices that are 'Down'.  The goal of the table is to show what device went down and when, and then when it came back up and the total time it took to come back up.
The table output should look like:
abcd-s-2-01,Down,<downdate>,<update>,<totaltime>  *where update is the outagedate when type=up.

The trouble I am having is figuring out how to get the UpDate and TotalTime.  I can retrieve the first 3 columns from the other table because those are listed on one row.  I am having problems trying to retrieve the outageDate and TotalTime when Type=Up and inserting it into my new table.

I tried running two strSQL statements (one where outagetype=down and the other where outagetype=up) and compare DeviceName but the second SQL Query (where type=up) doesn't produce the same devicename data.  For example:

SQL1 produces:
devicename,outagetype,downdate
abcd-s-2-1, Down, 2010-06-01 17:00:37
abcd-s-2-1, Down, 2010-06-01 19:00:15
xyz-s-2-1, Down, 2010-06-01 18:00:01
xyz-s-2-1,Down,2010-06-05 07:05:49
xyz-s-2-1,Down,2010-06-10 12:15:56

SQL2 produces:
devicename,outagetype,downdate,outagedate,totaltime
abcd-s-2-1,UP, 2010-06-01 17:00:37, 2010-06-01 17:15:00, 0.23
abcd-s-2-1, UP, 2010-06-01 19:00:15, 2010-06-01 19:30:18, 0.51
xyz-s-2-1, UP, 2010-06-01 18:00:01, 2010-06-01 19:00:00, 1.00
xyz-s-2-1,UP,2010-06-05 07:05:49, 2010-06-05 09:35:25, 2.50
xyz-s-2-1,UP,2010-06-10 12:15:56, 2010-06-11 11:10:10, 22.90
xyz-s-2-1,UP,2010-06-06 10:22:00, 2010-06-07 01:11:41, 20.85

as you can see, SQL2 has an extra entry that isn't in SQL1 query results.  When I do a recordset to compare the two device names (objRS.Fields(name)=objRS1.Fields(name)) I get null values all over the place or nothing at all becaue when SQL2 <> SQL1 it messes up the rest of the recordset Loop.

The simple code I have is:
objRS = SQL1
objRS1=SQL2
Do until objRS.EOF
if objRS(name) = objRS1(name)
then up_date = objRS1(outagedate) else
up_date = null

This works unitl I get to the point where there are extra results from SQL2 that don't compare to SQL1 (or vice versa).

Is there a not so complicated way to achieve this in VB? I've been trying to do it for two days and I am hitting a mental block.

If you need more clarity let me know.

Answer : How do compare two fields and based on a True comparison input into another field?

Assuming having this data in your table
devicename, outagetype, downdate, outagedate, totaltime
acbd-s-2-1      DOWN      2010-05-05 15:00:00.000      NULL      NULL
acbd-s-2-1      UP      2010-05-05 15:00:00.000      2010-05-05 18:15:00.000      3.25
acbd-s-2-1      DOWN      2010-05-06 13:00:00.000      NULL      NULL
acbd-s-2-1      UP      2010-05-06 13:00:00.000      2010-05-06 13:45:00.000      0.75
acbd-s-2-1      DOWN      2010-05-10 11:00:00.000      NULL      NULL
xyz-b-23-1      DOWN      2010-04-05 12:12:00.000      NULL      NULL
xyz-b-23-1      UP      2010-04-05 12:12:00.000      2010-04-05 13:15:00.000      1.01
xyz-b-23-1      DOWN      2010-05-05 11:00:00.000      NULL      NULL
xyz-b-23-1      UP      2010-05-05 11:00:00.000      2010-05-05 14:05:00.000      3.02
xyz-b-23-1      DOWN      2010-05-06 11:15:00.000      NULL      NULL

if you ran this query
select A.*,B.* from
(select * from tblOutage where OutageType = 'Down') A
inner join
(SELECT * from tblOutage where OutageType = 'Up') B
on A.Devicename=B.Devicename AND A.downdate=b.downdate

you have this result
devicename        outagetype   downdate                outagedate  totaltime  devicename    outagetype   downdate                outagedate              totaltime
----------------- ------------ ----------------------- ----------- ---------- ------------- ------------ ----------------------- ----------------------- ------------
acbd-s-2-1        DOWN         2010-05-05 15:00:00.000 NULL        NULL       acbd-s-2-1    UP           2010-05-05 15:00:00.000 2010-05-05 18:15:00.000 3.25
acbd-s-2-1        DOWN         2010-05-06 13:00:00.000 NULL        NULL       acbd-s-2-1    UP           2010-05-06 13:00:00.000 2010-05-06 13:45:00.000 0.75
xyz-b-23-1        DOWN         2010-05-05 11:00:00.000 NULL        NULL       xyz-b-23-1    UP           2010-05-05 11:00:00.000 2010-05-05 14:05:00.000 3.02
xyz-b-23-1        DOWN         2010-04-05 12:12:00.000 NULL        NULL       xyz-b-23-1    UP           2010-04-05 12:12:00.000 2010-04-05 13:15:00.000 1.01

(4 row(s) affected)


Random Solutions  
 
programming4us programming4us