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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Simple If...Else logic not working

Author  Topic 

craigwg
Posting Yak Master

154 Posts

Posted - 2009-07-28 : 11:52:53
Hi!

How do I make my If statement work? I think my problem is setting the variable equal to the results of a select statement. Basically my logic is this: If the server version is 2000, then run Code X, otherwise run code Y. This was my approach to it, but I am open to other ideas. Here is what I have:


DECLARE @version sql_variant
select @version=SERVERPROPERTY('productversion')

if @version like '8%'

--for 2000 servers
Code X
ELSE
--for 2005 servers
Code Y


Any ideas?

Craig Greenwood

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-07-28 : 12:38:13
[code]
declare @f sql_variant
select @f = SERVERPROPERTY('productversion')
if convert(varchar(20),@f) like '8%'
begin
select 1
end
else
begin
select 2
end[\code]

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -