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
 Help with function

Author  Topic 

tocroi72
Yak Posting Veteran

89 Posts

Posted - 2006-04-19 : 09:13:53
Hello all,
Can someone please tell me what is wrong with the below function, i get an error from it
CREATE FUNCTION f_PingServer (@servername varchar(50))
RETURN integer
AS
BEGIN
DECLARE @strCmd VARCHAR(100)
DECLARE @result integer

SELECT @strCmd = 'ping ' + @servername
Execute @result = Master..xp_cmdShell @strCmd , no_output
If @result = 0
return 0
else
return 1
END
below are error message
Server: Msg 156, Level 15, State 1, Procedure f_PingServer, Line 2
Incorrect syntax near the keyword 'RETURN'.
Server: Msg 178, Level 15, State 1, Procedure f_PingServer, Line 12
A RETURN statement with a return value cannot be used in this context.
Server: Msg 178, Level 15, State 1, Procedure f_PingServer, Line 14
A RETURN statement with a return value cannot be used in this context.

Thanks.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-19 : 09:29:52
Try
CREATE FUNCTION f_PingServer (@servername varchar(50))
RETURNs integer
AS
BEGIN
DECLARE @strCmd VARCHAR(100)
DECLARE @result integer

SELECT @strCmd = 'ping -n 1 ' + @servername
Execute @result = Master..xp_cmdShell @strCmd , no_output
return (@result)
end


Madhivanan

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

tocroi72
Yak Posting Veteran

89 Posts

Posted - 2006-04-19 : 09:34:42
thank you !!! i did try return @result but it didn't work , then i tried what i posted - didn't work either - forgot about the () ...
Thank you so much.

Go to Top of Page

tocroi72
Yak Posting Veteran

89 Posts

Posted - 2006-04-19 : 09:38:01
i forgot to ask you , what ping -n 1 does? Please execuse me for lacking SQL knowlege
Thanks
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-04-19 : 21:06:56
it's not sql, it's a dos command,

open a command prompt and type ping/?, this will show you the parameters...

--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -