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.
| 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 bitASbegin 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 OptimizerTG |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
|
|
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!! |
 |
|
|
|
|
|