Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Server Version (T-SQL)


SQL Server Version (T-SQL)

Author
Message
river1
river1
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1030 Visits: 1361
I need that this command returns if i'm using SQL Server 2000 or SQL Server 2005 or SQL Server 2008:

select
serverproperty ('productversion')


I know that i need to do a CASE T-SQL, who can i do this?


Thank you
Steve Cullen
Steve Cullen
SSChasing Mays
SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)

Group: General Forum Members
Points: 629 Visits: 1226
select @@VERSION

Converting oxygen into carbon dioxide, since 1955.


river1
river1
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1030 Visits: 1361
yap, that i know, but in this case what i was trying to achieve was making it return the version using a case , and if it returns 8, than it's 2000 if it returns 9 then it's 2005 if it returns 10 it's SQL Server 2008.

My difficulty is in the case command.

Can you help?


Thank you
Steve Cullen
Steve Cullen
SSChasing Mays
SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)

Group: General Forum Members
Points: 629 Visits: 1226
What are you trying to do with the case statement?

Converting oxygen into carbon dioxide, since 1955.


Lowell
Lowell
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17386 Visits: 39355
i would use the PARSENAME function to return the 8/9/10:

select serverproperty ('productversion') --9.00.4035.00
select parsename(convert(varchar,serverproperty ('productversion')),4) --"9"




Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

river1
river1
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1030 Visits: 1361
when i do this command:


select
serverproperty ('productversion')


if the first digit returned by the string is 8 then 2000
if the first digit returned by the string is 9 then 2005
..........
Lowell
Lowell
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17386 Visits: 39355
easy to grab what you need; here's a better example:


select
parsename(convert(varchar,serverproperty ('productversion')),4) As T4,
parsename(convert(varchar,serverproperty ('productversion')),3) As T3,
parsename(convert(varchar,serverproperty ('productversion')),2) As T2,
parsename(convert(varchar,serverproperty ('productversion')),1) As T1
--results:
T4 T3 T2 T1
-- --- ----- ---
9 00 4035 00



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

river1
river1
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1030 Visits: 1361
thank you lowell
Steve Cullen
Steve Cullen
SSChasing Mays
SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)

Group: General Forum Members
Points: 629 Visits: 1226
river1 (2/25/2010)
when i do this command:


select
serverproperty ('productversion')


if the first digit returned by the string is 8 then 2000
if the first digit returned by the string is 9 then 2005
..........

select case when cast(serverproperty ('productversion') as varchar(2)) like '8%' then '2000'
when cast(serverproperty ('productversion') as varchar(2)) like '9%' then '2005'
when cast(serverproperty ('productversion') as varchar(2)) like '10%' then '2008'
end



Converting oxygen into carbon dioxide, since 1955.


WayneS
WayneS
SSCertifiable
SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)SSCertifiable (6.9K reputation)

Group: General Forum Members
Points: 6861 Visits: 10429
Based on what Lowell started, how does this work for you?
select case convert(tinyint,PARSENAME(convert(varchar(20),SERVERPROPERTY('productversion')),4))
when 8 then 2000
when 9 then 2005
when 10 then 2008
end



Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search