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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to use @@Servername Variable!!

Author  Topic 

PatDeV
Posting Yak Master

197 Posts

Posted - 2005-11-03 : 15:30:44
Hi all,

How can i make the change to user the @@servername variable so when I run the out of a different server I don’t have to change the code. I want to make change so I don't have to put the server name (such as @@servername = testserver) how can i define that



CREATE FUNCTION fIsProduction ()
returns bit
AS
begin
declare @Prod bit
SELECT @Prod =case when @@servername = 'testServer'
then 1 else 0 end
return @Prod
end



Thanks

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-11-03 : 15:50:08
If you're production server is named "testServer" then you code will work. What problem are you having?

hint:
when you call this function you'll need to qualify the name.
ie: select dbo.fisProduction()

EDIT:
it's possible that your server lost the appropriate values in sysServers to know it's own name. Confirm that "select @@servername" actually returns the server name. If not you can call sp_addserver using the @local variable. (see Books Online for sp_addserver) An alternative is to use: serverproperty('servername')

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-03 : 15:53:49
[wooooosh]
Huh?
[/wooooosh]




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-11-03 : 15:57:31
quote:
Originally posted by X002548

[wooooosh]
Huh?
[/wooooosh]


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx



I don't ask, I just respond...


Be One with the Optimizer
TG
Go to Top of Page

PatDeV
Posting Yak Master

197 Posts

Posted - 2005-11-03 : 16:00:58
I want to use only @@Servername where I don't have to hard code the server name in code!!
so if i run that function from different server it can return 0!!

hope this make sense!!
Go to Top of Page
   

- Advertisement -