Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to modify this query to get the row count

Author  Topic 

kshahzad
Starting Member

45 Posts

Posted - 2013-07-04 : 01:15:45
I want to modify this query to
return row count


DECLARE @dCurrentTimeDATETIME

DECLARE @dCurrentTimeMinus5DATETIME


SET @dCurrentTime=GETDATE()

SET @dCurrentTimeMinus5=DATEADD(minute,-5, @dCurrentTime)


--Return lIDS for only sessions last accessed in the last 5 minutes

SELECT lID,MAX(dLastAccessed)

FROM SessionState_Variables

WHERE dLastAccessedBETWEEN @dCurrentTimeMinus5AND @dCurrentTime

GROUPBY lID

ORDERBY 2DESC

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-04 : 01:24:11
[code]
DECLARE @dCurrentTimeDATETIME

DECLARE @dCurrentTimeMinus5DATETIME


SET @dCurrentTime=GETDATE()

SET @dCurrentTimeMinus5=DATEADD(minute,-5, @dCurrentTime)


--Return lIDS for only sessions last accessed in the last 5 minutes

SELECT COUNT(*)
FROM SessionState_Variables
WHERE dLastAccessed =
(SELECT MAX(dLastAccessed)

FROM SessionState_Variables

WHERE dLastAccessed BETWEEN @dCurrentTimeMinus5AND @dCurrentTime
)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kshahzad
Starting Member

45 Posts

Posted - 2013-07-04 : 19:12:05
this worked thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-05 : 01:26:57
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -