all groups > sql server (alternate) > december 2006 >
You're in the

sql server (alternate)

group:

server version



server version fireball
12/27/2006 3:35:05 PM
sql server (alternate): I need to test, wheather my scripts run under proper instance version (ie.
if it is 2005).
I only know @@VERSION, but taht's not it. Any suggestions?


Re: server version John Bell
12/27/2006 8:16:55 PM
Hi

The SERVERPROPERTY function will give you similar information see
http://sqlserver2000.databases.aspfaq.com/how-do-i-know-which-version-of-sql-server-i-m-running.html

John

[quoted text, click to view]

Re: server version fireball
12/28/2006 10:38:34 AM
I will try to make myself more clear:
can I stop my script when running under wrong version of SqlServer?

Re: server version John Bell
12/28/2006 12:20:42 PM
Hi

You can test the version you are using and make the code run conditional on
that setting such as

IF CAST(LEFT(CAST(SERVERPROPERTY('productversion') AS varchar(30)),1) AS
smallint) < 9 GOTO EndofScript
PRINT CAST(LEFT(CAST(SERVERPROPERTY('productversion') AS varchar(30)),1) AS
smallint)
EndofScript:

John

[quoted text, click to view]

Re: server version fireball
12/28/2006 5:13:02 PM
U¿ytkownik "John Bell" <jbellnewsposts@hotmail.com> napisa³ w wiadomo¶ci
news:4593b698$0> > IF CAST(LEFT(CAST(SERVERPROPERTY('productversion') AS
varchar(30)),1) AS
[...]
I love newsgroups :-)



Re: server version John Bell
12/29/2006 9:11:26 AM
Hi

Regarding your other thread "prompting users", as you are using SQL 2005
then you can make your script execute particular actions by setting
variables and passing them to SQLCMD. These variables can then set by
prompting the user in a batch script or WMI script and then within your SQL
script they can be tested. There is more on this in Books Online.

John

[quoted text, click to view]

Re: server version fireball
12/29/2006 10:26:39 AM
U¿ytkownik "John Bell" <jbellnewsposts@hotmail.com> napisa³ w wiadomo¶ci
news:4594dbc2$0

[quoted text, click to view]
thx, I will read Books Online about, - any sigle simple example wolud be
helpful though.


Re: server version John Bell
12/29/2006 10:56:53 AM
Hi

You will create a new batch if you have a GO statement. You could use
RAISERROR instead as others have suggested.

John

[quoted text, click to view]

Re: server version fireball
12/29/2006 11:33:09 AM
U¿ytkownik "John Bell" <jbellnewsposts@hotmail.com> napisa³ w wiadomo¶ci
news:4593b698$0

[quoted text, click to view]

"...GOTO cannot go to a label outside the batch."
- is it possible to have an entire script as a single batch?

Thanks for helping with newbie questions.

Re: server version Hugo Kornelis
12/29/2006 8:57:38 PM
[quoted text, click to view]

Hi Fireball,

That depends on what is in the script. There is no length limit that I
know of (there probably is SOME length limit, but so sky high that
you'll never get to it for normal work). But there are some statements
that have to run in a seperate batch.

--
Re: server version Erland Sommarskog
12/29/2006 10:41:51 PM
Hugo Kornelis (hugo@perFact.REMOVETHIS.info.INVALID) writes:
[quoted text, click to view]

And there are other statements that cannot be in the same batch, for
instance:

ALTER TABLE tbl ADD somenewcol int
UPDATE tbl SET somenewcol = 4711

This will fail to compile, since the new column does not exist when the
batch is compiled.

But this can be dealt with by putting such statments in EXEC().


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: server version fireball
1/5/2007 10:58:04 AM
Uzytkownik "Hugo Kornelis" <hugo@perFact.REMOVETHIS.info.INVALID> napisal w

[quoted text, click to view]

do I need to redeclare all variables (and re-set it's values) I still use
after starting new batch in my script? :O

Re: server version Erland Sommarskog
1/6/2007 1:59:21 PM
fireball (fireball@onet.kropka.eu) writes:
[quoted text, click to view]

The scope of a variable is a batch. But you can run these commands that
require a separate batch from EXEC().


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
AddThis Social Bookmark Button