IF (EXISTS(Select * from sys.systable where LCase(table_name) = LCase('v_Tasks')))
THEN Drop view v_Tasks
END IF

GO

create view
  DBA.v_Tasks
  as select TaskID=Tasks.id,
    Active=Tasks.active,
    SourceID=Source.id,
    SourceName=Source.name,
    SourceDesc=Source.description,
    SourceStatus=(select Statuses.name from DBA.Statuses where Statuses.id = Tasks.source_status),
    SourceConnStatus=(select Statuses.name from DBA.Statuses where Statuses.id = Tasks.source_conn_status),
    SourceHandleID=SHandle.id,
    SorceHandle=SHandle.name,
    SourceDriver=SHandle.Driver,
    DestID=Dest.id,
    DestName=Dest.name,
    DestDesc=Dest.description,
    DestStatus=(select Statuses.name from DBA.Statuses where Statuses.id = Tasks.dest_status),
    DestConnStatus=(select Statuses.name from DBA.Statuses where Statuses.id = Tasks.dest_conn_status),
    DestHandleID=DHandle.id,
    DestHandle=DHandle.name,
    DestDriver=DHandle.Driver,
    Interval=Tasks.interval,
    NextRun=Tasks.next_run from
    DBA.Tasks,
    DBA.Objects as Source,
    DBA.Objects as Dest,
    DBA.Handles as SHandle,
    DBA.Handles as DHandle where
    Source.id = Tasks.source_id and
    Dest.id = Tasks.dest_id and
    SHandle.id = Source.handle_id and
    DHandle.id = Dest.handle_id order by
    TaskID asc
-- [v.1 20.Feb.2008] - Yanko, created
-- [v.2 16.11.2010] - Chavdar - changed order columns (order in MainUnit {lvOperations}) 
