Solved

Find average subscription time (calculate dates)

Posted on 2013-11-14
3
350 Views
Last Modified: 2013-11-15
Hi!

I have a table called "tblUserLog" that contains information about deleted users:

---------------------
tblUserLog
---------------------
UserName (varchar)
CreateDate (datetime)
LogDate (datetime)
SiteId (smallint)

I need to create a Stored Procedure that returns the average time between CreateDate (user registration) and LogDate (user deleted) where  SiteId = '2' and CreateDate > '2013-01-01'.

I need this to find out how many days an average users is registered. Hope someone please can help me solving this :)

Thanks!
0
Comment
Question by:webressurs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 100 total points
ID: 39648756
select avg(timediff) as avgtime from
(select datediff('dd',createdate, logdate) as timediff
 from yourtable
 where siteid = '2' and createdate > '2013-01-01') as x
0
 
LVL 11

Accepted Solution

by:
jasonduan earned 400 total points
ID: 39648766
Try this:

SELECT AVG(DATEDIFF(DAY, CreateDate, LogDate))
FROM tblUserLog
where  SiteId = '2' and CreateDate > '2013-01-01'
0
 
LVL 1

Author Closing Comment

by:webressurs
ID: 39650837
Thanks!!

Jasonduan code worked perfect!

Awking00 code needed a tiny adjustment:

select avg(timediff) as avgtime from
(select datediff(day,createdate, logdate) as timediff
 from yourtable
 where siteid = '2' and createdate > '2013-01-01') as x
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question