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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 need help with a calculated field

Author  Topic 

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-10-09 : 04:46:35
Hi i have a query like so:

select last_action_time
from clicky_recent_visitors

this generates data like following:

2009-10-09 09:29:00.000
2009-10-09 09:28:00.000
2009-10-09 09:25:00.000
2009-10-09 09:23:00.000
2009-10-09 09:22:00.000

What i would like is to create another column in the clicky_recent_visitors table called visitor_active which will be a bit field. Now I want this field to be a calculated field i.e a formula. I would like this formula to set the value in this field to 1 if the last_action_time is less than 30 mins from the current time. And set the value in this field to 0 if the last_action_time is greater than 30 mins from the current time.

I haven't done anything like this before. Can anyone please help me?

Thanks
Zubair

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-09 : 04:58:17
update my_table set visitor_active =case when
datediff(mi,last_action_time,getdate()) <30 then '1'
else '0' end

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

zubair
Yak Posting Veteran

67 Posts

Posted - 2009-10-09 : 05:11:10
thx senthil
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-10-09 : 05:23:00
quote:
Originally posted by zubair

thx senthil



Welcome

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -