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
 What's wrong with this function?

Author  Topic 

dmilam
Posting Yak Master

185 Posts

Posted - 2010-04-14 : 16:51:39
I get only "Command(s) completed successfully", not the string I'm trying to process and see the result of.


USE T;

-- Verify that the function does not exist.
IF OBJECT_ID ( N'fn_Trim', N'FN' ) IS NOT NULL
DROP FUNCTION fn_Trim;
GO

CREATE FUNCTION fn_Trim(@string VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@string))
END;
GO

/* Should return 'text' */
EXEC T..fn_Trim @string = ' text '

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2010-04-14 : 16:57:58
func is fine,

try select '|'+dbo.fn_trim(' text ')+'|'

quote:
Originally posted by dmilam

I get only "Command(s) completed successfully", not the string I'm trying to process and see the result of.


USE T;

-- Verify that the function does not exist.
IF OBJECT_ID ( N'fn_Trim', N'FN' ) IS NOT NULL
DROP FUNCTION fn_Trim;
GO

CREATE FUNCTION fn_Trim(@string VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@string))
END;
GO

/* Should return 'text' */
EXEC T..fn_Trim @string = ' text '

Go to Top of Page

dmilam
Posting Yak Master

185 Posts

Posted - 2010-04-14 : 17:07:34
Thanks; I get

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.

with

select '|'+T..fn_Trim(' text ')+'|'
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-04-14 : 17:31:54
quote:
Originally posted by dmilam

Thanks; I get

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.

with

select '|'+T..fn_Trim(' text ')+'|'



You might try running the command that was suggested by hanbingl:
select '|'+dbo.fn_trim(' text ')+'|'


CODO ERGO SUM
Go to Top of Page

dmilam
Posting Yak Master

185 Posts

Posted - 2010-04-14 : 17:42:44
I did, and got

Msg 4121, Level 16, State 1, Line 8
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fn_trim", or the name is ambiguous.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-14 : 17:52:50
Replace dbo with whoever owns the function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dmilam
Posting Yak Master

185 Posts

Posted - 2010-04-14 : 18:10:37
That did it; thanks, Tara!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-15 : 13:24:27


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -