문제

I'm trying to prepare sql script which will be triggered periodically and will behave differently on MS SQL Server Enterprise edition than others. I know that I can check edition by:

SELECT SERVERPROPERTY('edition')

so i thought that it can work like this:

IF EXISTS 
    (SELECT SERVERPROPERTY('edition') as edition WHERE edition LIKE '%Enterprise')
BEGIN
    print 'script for enterprise edition'
END
ELSE
BEGIN
    print 'script for other verisons'
END

but I can't refer to field aliases in the WHERE clause and get error "Invalid column name 'edition'.", so I tried to use CTE:

WITH Test AS (SELECT SERVERPROPERTY('edition') as edition)
SELECT * FROM Test WHERE edition LIKE '%Enterprise'

but it didn't work either ("Argument data type sql_variant is invalid for argument 1 of like function.")

Do you have any suggestion how to achieve behavior dependent on edition?

도움이 되었습니까?

해결책

Here's the check:

if (cast(serverproperty('edition') as varchar) like '%enterprise%')
    print 'script for enterprise edition'
else
    print 'script for other verisons'

다른 팁

%Store Results of SERVERPROPERTY to a variable:

DECLARE @Edition SYSNAME
SELECT @Edition = CAST(SERVERPROPERTY('Edition') AS SYSNAME)

IF (@Edition LIKE '%Enterprise%')
BEGIN
    print 'script for enterprise edition'
END
ELSE
BEGIN
    print 'script for other verisons'
END

EDIT: Updated as per comment by @marc_s

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top