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
 General SQL Server Forums
 New to SQL Server Programming
 Problems with syntax in an ALTER query

Author  Topic 

fixertool
Starting Member

2 Posts

Posted - 2011-11-25 : 09:34:41
I cannot solve this syntax problem. Thanks in advance

1 USE [someDB]
2 GO
3 /************/
4 SET ANSI_NULLS ON
5 GO
6 SET QUOTED_IDENTIFIER ON
7 GO
8 ALTER FUNCTION [dbo].[increment]()
9 RETURNS INT
10 AS
11 BEGIN
12 DECLARE @auto INT,
13 @result INT
14
15 IF (SELECT COUNT(*) FROM sampleTable) > 0
16 BEGIN
17 SELECT @auto = MAX(ord) FROM sampleTable
18 @result = @auto + 1
19 END
20 ELSE
21 BEGIN
22 @result = 0
23 END;
24
25 RETURN @result
26 END

Msg 102, Level 15, State 1, Procedure increment, Line 11
Incorrect syntax near '@result'.
Msg 102, Level 15, State 1, Procedure increment, Line 15
Incorrect syntax near '@result'.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-25 : 09:43:36
1 USE [someDB]
2 GO
3 /************/
4 SET ANSI_NULLS ON
5 GO
6 SET QUOTED_IDENTIFIER ON
7 GO
8 ALTER FUNCTION [dbo].[increment]()
9 RETURNS INT
10 AS
11 BEGIN
12 DECLARE @auto INT,
13 @result INT
14
15 IF (SELECT COUNT(*) FROM sampleTable) > 0
16 BEGIN
17 SELECT @auto = MAX(ord) FROM sampleTable
18 select @result = @auto + 1
19 END
20 ELSE
21 BEGIN
22 select @result = 0
23 END;
24
25 RETURN @result
26 END



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

fixertool
Starting Member

2 Posts

Posted - 2011-11-25 : 10:08:06
Thank you! Problem solved.
Go to Top of Page
   

- Advertisement -