A user defined function question 
Author Message
 A user defined function question

I am learning to build an user defined function. I have
the following codes:

create table tmp (f1 char(1))
GO
insert tmp values ('A')
insert tmp values ('B')
GO

CREATE FUNCTION fn_try

RETURNS CHAR(2)
AS
BEGIN




END
GO

SELECT fn_try(f1) FROM tmp

I keep getting a message saying, 'Incorrect syntex near
the keyword 'SELECT'.
I know I can use CASE but I just want to try if I can do
it in a user defined function.



Mon, 13 Feb 2006 15:09:08 GMT
 A user defined function question

It works very well for me.Except that you should execute it as follows.

Ex:
SELECT dbo.fn_try(f1) FROM tmp--where dbo is the owner of the function.

--
-Vishal


Quote:
> I am learning to build an user defined function. I have
> the following codes:

> create table tmp (f1 char(1))
> GO
> insert tmp values ('A')
> insert tmp values ('B')
> GO

> CREATE FUNCTION fn_try

> RETURNS CHAR(2)
> AS
> BEGIN




> END
> GO

> SELECT fn_try(f1) FROM tmp

> I keep getting a message saying, 'Incorrect syntex near
> the keyword 'SELECT'.
> I know I can use CASE but I just want to try if I can do
> it in a user defined function.



Mon, 13 Feb 2006 15:18:59 GMT
 A user defined function question

For a scalar UDF, you need to use two-part naming:

SELECT dbo.fn_try(f1) FROM tmp

--
Tom

---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql

I am learning to build an user defined function. I have
the following codes:

create table tmp (f1 char(1))
GO
insert tmp values ('A')
insert tmp values ('B')
GO

CREATE FUNCTION fn_try

RETURNS CHAR(2)
AS
BEGIN




END
GO

SELECT fn_try(f1) FROM tmp

I keep getting a message saying, 'Incorrect syntex near
the keyword 'SELECT'.
I know I can use CASE but I just want to try if I can do
it in a user defined function.



Mon, 13 Feb 2006 15:14:47 GMT
 A user defined function question
SELECT dbo.fn_try(f1) FROM tmp


Quote:
> I am learning to build an user defined function. I have
> the following codes:

> create table tmp (f1 char(1))
> GO
> insert tmp values ('A')
> insert tmp values ('B')
> GO

> CREATE FUNCTION fn_try

> RETURNS CHAR(2)
> AS
> BEGIN




> END
> GO

> SELECT fn_try(f1) FROM tmp

> I keep getting a message saying, 'Incorrect syntex near
> the keyword 'SELECT'.
> I know I can use CASE but I just want to try if I can do
> it in a user defined function.



Mon, 13 Feb 2006 15:16:52 GMT
 A user defined function question
Hi,

Call the function using dbo, this should help

SELECT dbo.fn_try(f1) FROM tmp

Hope this helps

Chris Taylor


Quote:
> I am learning to build an user defined function. I have
> the following codes:

> create table tmp (f1 char(1))
> GO
> insert tmp values ('A')
> insert tmp values ('B')
> GO

> CREATE FUNCTION fn_try

> RETURNS CHAR(2)
> AS
> BEGIN




> END
> GO

> SELECT fn_try(f1) FROM tmp

> I keep getting a message saying, 'Incorrect syntex near
> the keyword 'SELECT'.
> I know I can use CASE but I just want to try if I can do
> it in a user defined function.



Mon, 13 Feb 2006 15:24:26 GMT
 A user defined function question
Hi Jane,
You have to prefix the function name with the owner. The follwoing works on
my server:

create table tmp (f1 char(1))
GO
insert tmp values ('A')
insert tmp values ('B')
GO

CREATE FUNCTION fn_try

RETURNS CHAR(2)
AS
BEGIN




END
GO

SELECT dbo.fn_try(f1) FROM tmp

DROP TABLE tmp
DROP function fn_try

--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.


Quote:
> I am learning to build an user defined function. I have
> the following codes:

> create table tmp (f1 char(1))
> GO
> insert tmp values ('A')
> insert tmp values ('B')
> GO

> CREATE FUNCTION fn_try

> RETURNS CHAR(2)
> AS
> BEGIN




> END
> GO

> SELECT fn_try(f1) FROM tmp

> I keep getting a message saying, 'Incorrect syntex near
> the keyword 'SELECT'.
> I know I can use CASE but I just want to try if I can do
> it in a user defined function.



Mon, 13 Feb 2006 15:22:12 GMT
 
 [ 6 post ] 

 Relevant Pages 

1. user defined function question

2. User Defined Function Question

3. User defined function question

4. User-defined function question

5. call a user defined function from another user-defined function

6. Question on user defined function (SQL Server 2000)

7. Question about user-defined functions

8. Newbie questions on User-defined functions in SQL server

9. Question on user defined function (SQL Server 2000)

10. user-defined function client server question

11. questions on user-defined function

12. more question about adding values from user defined function


 
Powered by phpBB® Forum Software