Is there StartsWith or Contains in t sql with variables?
It seems like what you want is http://msdn.microsoft.com/en-us/library/ms186323.aspx.
In your example it would be (starts with):
set @isExpress = (CharIndex('Express Edition', @edition) = 1)
Or contains
set @isExpress = (CharIndex('Express Edition', @edition) >= 1)
StartsWith
a) left(@edition, 15) = 'Express Edition'
b) charindex('Express Edition', @edition) = 1
Contains
charindex('Express Edition', @edition) >= 1
Examples
left
function
set @isExpress = case when left(@edition, 15) = 'Express Edition' then 1 else 0 end
iif
function (starting with SQL Server 2012)
set @isExpress = iif(left(@edition, 15) = 'Express Edition', 1, 0);
charindex
function
set @isExpress = iif(charindex('Express Edition', @edition) = 1, 1, 0);
I would use
like 'Express Edition%'
Example:
DECLARE @edition varchar(50);
set @edition = cast((select SERVERPROPERTY ('edition')) as varchar)
DECLARE @isExpress bit
if @edition like 'Express Edition%'
set @isExpress = 1;
else
set @isExpress = 0;
print @isExpress