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 |
|
Oldfield
Starting Member
2 Posts |
Posted - 2009-06-23 : 05:38:50
|
| Hope this is a suitable/correct forum for this question - sorry if not...Is it possible to write a sql script that'll run some sql for 2000 if it's installed, or some other sql for 2005 or something else if version 7.. or something's installed - e.g. do nothing?I can get the server version with @@VERSION, I think.I can't seem to make it work in an if/else bit o' code.What it's for:For 2000 I'd do--create some users:EXEC sp_addlogin ...EXEC sp_addlogin ...but for 2005 I'd want to do :create login ...create login ...At the moment I have 2 scripts - with only that bit different. - Can it be put into the same script so users only have to run one, without thinking (or knowing) which version of sql server they have installed? |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-23 : 07:18:31
|
You can try:if @@version like '%Server 2005%'begin execendelsebegin createend No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-23 : 07:24:34
|
[code]IF CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(10)) LIKE '8.%' PRINT ' SQL Server 2000'ELSE IF CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(10)) LIKE '9.%' PRINT ' SQL Server 2005'ELSE IF CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR(10)) LIKE '10.%' PRINT ' SQL Server 2008'[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
Oldfield
Starting Member
2 Posts |
Posted - 2009-06-23 : 07:56:39
|
| Thanks Peso, and webfred of course. Perfect! Just what I was after.Thanks very much! |
 |
|
|
|
|
|