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 |
|
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 intASBEGIN declare @seqno int select @seqno = year(@today)ENDRETURN str(@seqno,4,0)END
I get an errorMsg 156, Level 15, State 1, Procedure GetId, Line 10Incorrect syntax near the keyword 'RETURN'.Msg 102, Level 15, State 1, Procedure GetId, Line 11Incorrect 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 intASBEGIN declare @seqno int select @seqno = year(@today)--RETURN str(@seqno,4,0)RETURN @seqno -- this is enough!END---run function asSELECT DBO.GETID(GETDATE()) |
 |
|
|
mayoorsubbu
Yak Posting Veteran
95 Posts |
Posted - 2010-07-11 : 02:17:59
|
| Thank you slimt_slimt |
 |
|
|
|
|
|