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)
 If Else Syntax Problem

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 mssg
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'IF'.


DECLARE @minutes INT, @word VARCHAR(255),@hours INT, @min INT, @second INT
SET @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)))
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 mssg
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'IF'.


DECLARE @minutes INT, @word VARCHAR(255),@hours INT, @min INT, @second INT
SET @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 do
Probably there may be easier way

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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?"

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -