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.
| Author |
Topic |
|
tmack
Starting Member
6 Posts |
Posted - 2006-01-30 : 22:49:23
|
| Hello, I need to use a if statement in stored procedures. What I need to know is the proper syntax because anything I try does not work.I need to check if 24 hours passed:datediff(hh, Users.LastLogin, GetDate())Should return the number of hours that has passed. I need to use this in the IF statement, and I need to check if it's > 24.Thanks =)! |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-01-30 : 23:00:21
|
| You can't use an if statement in a query.You canif (select Users.LastLogin - GetDate() from users where userid = @userid) > 24begin ......end....orselect * from users where Users.LastLogin - GetDate() > 24orselectcase when Users.LastLogin - GetDate() > 24 then 'a' else 'b' endfrom users==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-30 : 23:54:08
|
| wont this work in SQL Server 2005?select * from users where datediff(hh, Users.LastLogin, GetDate())>24MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|