dbTalk Databases Forums  

I love this recursive stuff

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss I love this recursive stuff in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jim Diaz
 
Posts: n/a

Default I love this recursive stuff - 12-05-2009 , 09:59 AM






WITH RECURSIVE
Connections (ConnectionId, UserId, IPAddress, CommunicationLink,
Application, LoginTimestamp, ConnectionMinutes, LastTimestamp, IdleMinutes)
AS
(
( SELECT next_connection( NULL ) AS ConnectionId,
connection_property( 'Userid', ConnectionId) AS UserId,
connection_property( 'NodeAddress', ConnectionId) AS IPAddress,
connection_property( 'CommLink', ConnectionId) AS
CommunicationLink,
connection_property( 'AppInfo', ConnectionId) AS Application,
CAST(connection_property( 'LoginTime', ConnectionId) AS CHAR(19))
AS LoginTimestamp,
DATEDIFF(Minute, connection_property( 'LoginTime', ConnectionId),
Current Timestamp ) AS ConnectionMinutes,
CAST(connection_property( 'LastReqTime', ConnectionId) AS
CHAR(19)) AS LastTimestamp,
DATEDIFF(Minute, connection_property( 'LastReqTime',
ConnectionId), Current Timestamp ) AS IdleMinutes
FROM Dummy AS Seed
)
UNION ALL
( SELECT next_connection( Seed.ConnectionId ) AS ConnectionId,
connection_property( 'Userid', ConnectionId) AS UserId,
connection_property( 'NodeAddress', ConnectionId) AS IPAddress,
connection_property( 'CommLink', ConnectionId) AS
CommunicationLink,
connection_property( 'AppInfo', ConnectionId) AS Application,
CAST(connection_property( 'LoginTime', ConnectionId) AS CHAR(19))
AS LoginTimestamp,
DATEDIFF(Minute, connection_property( 'LoginTime', ConnectionId),
Current Timestamp ) AS ConnectionMinutes,
CAST(connection_property( 'LastReqTime', ConnectionId) AS
CHAR(19)) AS LastTimestamp,
DATEDIFF(Minute, connection_property( 'LastReqTime',
ConnectionId), Current Timestamp ) AS IdleMinutes
FROM Dummy,
Connections AS Seed
WHERE ConnectionId IS NOT NULL
)
)
SELECT * FROM Connections

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.