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 |
|
LOOKUP_BI
Constraint Violating Yak Guru
295 Posts |
Posted - 2010-02-16 : 16:42:38
|
| Can someone explain why I'm getting following error mssgMsg 156, Level 15, State 1, Line 10Incorrect syntax near the keyword 'IF'.DECLARE @minutes INT, @word VARCHAR(255),@hours INT, @min INT, @second INTSET @minutes = ABS(DATEDIFF(MINUTE,'10/16/2009 11:36:47 AM','10/17/2009 4:43:55 PM')) IF @minutes = 0 SET @word = '00' ELSE BEGIN SET @word = '' IF @minutes >= (24*60) set @hours=(RTRIM(@minutes/(24*60)) IF LEN(@hours) < 2 SET @word = @word + '0' + @hours+' :' IF LEN(@hours) >= 2 SET @word = @word + @hours+' :' END |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-02-16 : 17:01:27
|
| Missing parenthesis:set @hours=(RTRIM(@minutes/(24*60))) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-17 : 00:39:03
|
| i really cant understand why you want to divide by 24*60 to convert minutes to hours? What you're doing is converting it to days------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-17 : 01:55:09
|
quote: Originally posted by LOOKUP_BI Can someone explain why I'm getting following error mssgMsg 156, Level 15, State 1, Line 10Incorrect syntax near the keyword 'IF'.DECLARE @minutes INT, @word VARCHAR(255),@hours INT, @min INT, @second INTSET @minutes = ABS(DATEDIFF(MINUTE,'10/16/2009 11:36:47 AM','10/17/2009 4:43:55 PM')) IF @minutes = 0 SET @word = '00' ELSE BEGIN SET @word = '' IF @minutes >= (24*60) set @hours=(RTRIM(@minutes/(24*60)) IF LEN(@hours) < 2 SET @word = @word + '0' + @hours+' :' IF LEN(@hours) >= 2 SET @word = @word + @hours+' :' END
In addition to posting the code, tell us what you want to doProbably there may be easier wayMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-17 : 01:56:44
|
I think there's indeed an easy way to what OP is trying to do ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-17 : 02:01:24
|
| Many people have approach of "How to do it?" than "Why do I do it?"MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|