Val*_*mas 86 sql t-sql sql-server-2008
我试图检测服务器是否正在运行Express Edition.
我有以下t sql.
DECLARE @edition varchar(50);
set @edition = cast((select SERVERPROPERTY ('edition')) as varchar)
print @edition
Run Code Online (Sandbox Code Playgroud)
在我的例子中, @edition = Express Edition (64-bit)
我该怎么办?(C#启发).
DECLARE @isExpress bit;
set @isExpress = @edition.StartsWith('Express Edition');
Run Code Online (Sandbox Code Playgroud)
Kir*_*huk 108
以..开始
a) left(@edition, 15) = 'Express Edition'
b) charindex('Express Edition', @edition) = 1
Run Code Online (Sandbox Code Playgroud)
包含
charindex('Express Edition', @edition) >= 1
Run Code Online (Sandbox Code Playgroud)
例子
left
功能
set @isExpress = case when left(@edition, 15) = 'Express Edition' then 1 else 0 end
Run Code Online (Sandbox Code Playgroud)
iif
功能(从SQL Server 2012开始)
set @isExpress = iif(left(@edition, 15) = 'Express Edition', 1, 0);
Run Code Online (Sandbox Code Playgroud)
charindex
功能
set @isExpress = iif(charindex('Express Edition', @edition) = 1, 1, 0);
Run Code Online (Sandbox Code Playgroud)
Gar*_*y.S 71
看起来你想要的是http://msdn.microsoft.com/en-us/library/ms186323.aspx.
在你的例子中它将是(开头):
set @isExpress = (CharIndex('Express Edition', @edition) = 1)
Run Code Online (Sandbox Code Playgroud)
或包含
set @isExpress = (CharIndex('Express Edition', @edition) >= 1)
Run Code Online (Sandbox Code Playgroud)
Tho*_*lle 35
我会用
like 'Express Edition%'
Run Code Online (Sandbox Code Playgroud)
例:
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
Run Code Online (Sandbox Code Playgroud)
小智 5
以下是对过滤数据时可以执行的操作的说明 - 最后,您只需将变量传递到需要的地方即可。
WHERE CustomerName LIKE 'a%'
--Finds any values that start with "a"
WHERE CustomerName LIKE '%a'
--Finds any values that end with "a"
WHERE CustomerName LIKE '%or%'
--Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%'
--Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a__%'
--Finds any values that start with "a" and are at least 3 characters in length
WHERE ContactName LIKE 'a%o'
--Finds any values that start with "a" and ends with "o"
SELECT * FROM my_table WHERE upper(my_column) LIKE 'SEARCHED%';
--Starts with, case insensitive
SELECT * FROM my_table WHERE upper(my_column) LIKE '%SEARCHED';
--Ends with, case insensitive
SELECT * FROM my_table WHERE upper(my_column) LIKE '%SEARCHED%';
--Contains, case insensitive
Run Code Online (Sandbox Code Playgroud)