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
 Old Forums
 CLOSED - General SQL Server
 Incorrect syntax near 'FUNCTION'

Author  Topic 

jawu
Starting Member

7 Posts

Posted - 2005-08-29 : 06:48:32
Hi, I want to call the Function in my Select Query. For that I wanted to create Function but when I tried to Create Function in Query Analyzer I was getting error
"Incorrect syntax near 'FUNCTION'".
After I have copied the Create function Example given in the help and tried to execute then also giving the same error result. What is the Exact reason? Very Urgent? Can you Help?
JAVED.

Javed Shaikh

Software Engineer
Macleods Pharma Ltd.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-29 : 06:52:37
Post the Create Function statement you used

Madhivanan

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

jawu
Starting Member

7 Posts

Posted - 2005-08-29 : 07:15:12
Hi, Madhivanan

The Function is:

USE pubs
GO
CREATE FUNCTION SalesByStore (@storeid varchar(30))
RETURNS TABLE
AS
RETURN (SELECT title, qty
FROM sales s, titles t
where t.title_id = s.title_id)




Javed Shaikh

Software Engineer
Macleods Pharma Ltd.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-29 : 07:19:29
There is nothing wrong with that function
After you created that Function in Query Analyser, run this

Select * from SalesByStore(1)

and see what you get

Madhivanan

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

jawu
Starting Member

7 Posts

Posted - 2005-08-29 : 07:26:20
but why I m getting the Error when I am trying to Create it. I am able to create the Procedure but not the function. I am very confused now. is there any setting or option or permission or anything else I am missing out.

Javed Shaikh

Software Engineer
Macleods Pharma Ltd.
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-08-30 : 09:27:46
Maybe this will fix it?

USE pubs
GO
CREATE FUNCTION dbo.SalesByStore (@storeid varchar(30))
RETURNS TABLE
AS
RETURN (SELECT title, qty
FROM sales s, titles t
where t.title_id = s.title_id)


Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2005-08-30 : 10:36:58
What compatibility level are you at? Functions requires 80.
Go to Top of Page

robg69
Starting Member

41 Posts

Posted - 2005-09-12 : 12:59:58
Oh yea, duh. What LarsG said. Change your compatibility level.
Go to Top of Page
   

- Advertisement -