I know that there is a way to check if the linked server is running.
I wanna know if there is a way to check it inside a function
I wrote this code:
create function dbo.Ck_DB_Stat
(@servername nvarchar (20))
returns bit
AS
BEGIN
declare @srvr nvarchar(128), @retval int, @res nvarchar (10)
declare @ck bit
set @srvr = @servername;
begin try
exec @retval = sys.sp_testlinkedserver @srvr;
set @ck = 1
end try
begin catch
set @retval = sign(@@error);
end catch;
if @retval <> 0
set @ck = 0
return @ck
END