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
 Error in Fuction

Author  Topic 

mayoorsubbu
Yak Posting Veteran

95 Posts

Posted - 2010-07-11 : 00:07:07
Dear All,

I want to create a function that returns an ID. The first four characters of the ID correspond to the current year. I created a small portion of the Function like so:

quote:
CREATE FUNCTION GetId
(@Today Datetime)
RETURNS int
AS
BEGIN
declare @seqno int
select @seqno = year(@today)
END

RETURN str(@seqno,4,0)
END


I get an error
Msg 156, Level 15, State 1, Procedure GetId, Line 10
Incorrect syntax near the keyword 'RETURN'.
Msg 102, Level 15, State 1, Procedure GetId, Line 11
Incorrect syntax near 'END'.


Please tell em why?

Thanks

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-07-11 : 01:37:17
i don't know what you are trying to achieve with this function but here is correct syntax:

CREATE FUNCTION dbo.GetId (@Today Datetime)
RETURNS int
AS
BEGIN
declare @seqno int
select @seqno = year(@today)
--RETURN str(@seqno,4,0)
RETURN @seqno -- this is enough!
END


---run function as
SELECT DBO.GETID(GETDATE())
Go to Top of Page

mayoorsubbu
Yak Posting Veteran

95 Posts

Posted - 2010-07-11 : 02:17:59
Thank you slimt_slimt
Go to Top of Page
   

- Advertisement -