March 22, 2011 at 10:16 am
This is an extension of this post...
http://www.sqlservercentral.com/Forums/Topic1080578-392-1.aspx
I originally posted the link above, but now I have another question similar in nature. When I started in my development career (loosely using the word development), I was a web developer. We used JavaScript to determine (pseudo) IF IE6 then... If IE7 then... IF IE8 then...
Is there a way in SQL 08 to do such a thing??? (I know this sounds dumb when I typed the question, but I thought I would ask...) IF mode = 80, then execute this script ELSE IF MODE = 90, then execute the script ELSE IF MODE = 100, then execute this script???
March 22, 2011 at 10:43 am
SELECT SERVERPROPERTY('productversion')
This returns it in the form of major.minor.build.
I know this is common in web code due to the vast compatibility differences and the fact that you have little choice which browser someone uses, but I'd tend to see it as having less use on SQL Server (certainly 2005 & 2008) due to the high level of compatibility between them and being able to certify your application for certain versions.
March 22, 2011 at 11:24 am
hi,
Have a look on this
declare @flg tinyint
Select @flg= case when cmptlevel=100 then 1 when cmptlevel=90 then 2 when cmptlevel=80 then 3 end
from master.dbo.sysdatabases
Select @flg
IF @flg=1 exec proc1
IF @flg=2 exec proc2
IF @flg=3 exec proc3
Thanks
Parthi
March 22, 2011 at 11:31 am
Perhaps I misunderstood the original question. Are you simply trying to find the compatibility mode of databases on a SQL Server 2008 instance rather than check the version of SQL Server you're running on?
If so, use sys.databases rather than sysdatabases (a deprecated SQL 2000 view) to achieve this.
March 22, 2011 at 11:41 am
parthi-1705 (3/22/2011)
hi,Have a look on this
declare @flg tinyint
Select @flg= case when cmptlevel=100 then 1 when cmptlevel=90 then 2 when cmptlevel=80 then 3 end
from master.dbo.sysdatabases
Select @flg
IF @flg=1 exec proc1
IF @flg=2 exec proc2
IF @flg=3 exec proc3
This looks good. Any way to execute a select statement instead of a proc?
March 22, 2011 at 1:31 pm
SQL_Padawan_Learner (3/22/2011)
parthi-1705 (3/22/2011)
hi,Have a look on this
declare @flg tinyint
Select @flg= case when cmptlevel=100 then 1 when cmptlevel=90 then 2 when cmptlevel=80 then 3 end
from master.dbo.sysdatabases
Select @flg
IF @flg=1 exec proc1
IF @flg=2 exec proc2
IF @flg=3 exec proc3
This looks good. Any way to execute a select statement instead of a proc?
As HowardW pointed out, the sysdatabases view is deprecated so you'll want to use sys.databases. Try this out:
DECLARE @compatibility_level TINYINT ;
-- get compat level for current DB
SELECT @compatibility_level = compatibility_level
FROM sys.databases
WHERE database_id = DB_ID() ;
IF @compatibility_level = 80
BEGIN
-- SQL 2000
SELECT column_name
FROM dbo.table_name ;
END
IF @compatibility_level = 90
BEGIN
-- SQL 2005
SELECT column_name
FROM dbo.table_name ;
END
IF @compatibility_level = 100
BEGIN
-- SQL 2008
SELECT column_name
FROM dbo.table_name ;
END
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply