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 |
|
nt86
Yak Posting Veteran
54 Posts |
Posted - 2010-01-13 : 10:13:59
|
| I want to write a simple IF statement in my stored procedure, im using SQL 2005. Basically 1) if the status on a record = 'OPEN' then i want to get todays date and then date difference in hours (hours and minutes if possible) between the startup_Time and todays date2)I only need to get this though if the result is greater than or equal to 24 3)Finally i need to insert this value if its greater than 24 into a hours_on field in my temp table.This is my attempt so far would appreciate if anyone could point out my mistakes and possibly show my how to get the result when its over >=24, the status field is in my temp table is being populated with data from a view. thanksIf STATUS = 'OPEN' Begin update #exceptiontemp SET hours_on = DATEDIFF(HOUR, startup_Time, GetDate()) Endniall |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-13 : 10:24:08
|
| [code]update #exceptiontempSET hours_on = DATEDIFF(HOUR, startup_Time, GetDate())where Status ='Open'AND DATEDIFF(HOUR, startup_Time, GetDate())>= 24[/code] |
 |
|
|
nt86
Yak Posting Veteran
54 Posts |
Posted - 2010-01-13 : 10:38:00
|
quote: Originally posted by visakh16
update #exceptiontempSET hours_on = DATEDIFF(HOUR, startup_Time, GetDate())where Status ='Open'AND DATEDIFF(HOUR, startup_Time, GetDate())>= 24
Works perfectly, Thank youniall |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-13 : 10:40:54
|
cheers |
 |
|
|
|
|
|
|
|