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 |
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2009-05-06 : 10:44:32
|
| Hi,I have the following:CASE WHEN (CONVERT(varchar, getdate(), 108) > '17:00:00') THEN CONVERT(varchar, getdate(), 108) - '17:00:00' ELSE '0' END AS end_timeObviously this statement will not work; because the varchar is invalid for subtract operator.Is there a way I can just keep this as a simple case statement, instead of writing a stored proc?ThanksFahad |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-05-06 : 10:59:05
|
| You can do this. Formatting should be done in the front-end, so I'll leave that to youJim declare @date datetimeset @date = '10/10/2008 17:00:00'select case when datepart(hour,@date) > 17 then dateadd(hour,-17,@date) else 0 end |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-05-07 : 02:47:09
|
| declare @date datetimeset @date = '10/10/2008 17:00:00'select case when datepart(hour,@date) > 17 then dateadd(hour,-17,@date)else dateadd(hour,0,@date)endMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-05-07 : 02:49:11
|
| ordeclare @date datetimeset @date = '10/10/2008 17:00:00'select case when datepart(hour,@date) > 17 then dateadd(hour,-17,@date)else @dateendMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|