我想做这样的事情:
declare @temp as varchar
set @temp='Measure'
if(@temp == 'Measure')
Select Measure from Measuretable
else
Select OtherMeasure from Measuretable
我想做这样的事情:
declare @temp as varchar
set @temp='Measure'
if(@temp == 'Measure')
Select Measure from Measuretable
else
Select OtherMeasure from Measuretable
两件事情:
采用:
DECLARE @temp VARCHAR(10)
SET @temp = 'm'
IF @temp = 'm'
SELECT 'yes'
ELSE
SELECT 'no'
VARCHAR(10)
表示 VARCHAR 最多可容纳 10 个字符。更多行为示例 -
DECLARE @temp VARCHAR
SET @temp = 'm'
IF @temp = 'm'
SELECT 'yes'
ELSE
SELECT 'no'
...将返回“是”
DECLARE @temp VARCHAR
SET @temp = 'mtest'
IF @temp = 'm'
SELECT 'yes'
ELSE
SELECT 'no'
...将返回“否”。
declare @temp as varchar
set @temp='Measure'
if(@temp = 'Measure')
Select Measure from Measuretable
else
Select OtherMeasure from Measuretable
你想要的是一个 SQL case 语句。它们的形式是:
select case [expression or column]
when [value] then [result]
when [value2] then [result2]
else [value3] end
或者:
select case
when [expression or column] = [value] then [result]
when [expression or column] = [value2] then [result2]
else [value3] end
在您的示例中,您追求的是:
declare @temp as varchar(100)
set @temp='Measure'
select case @temp
when 'Measure' then Measure
else OtherMeasure end
from Measuretable
你也可以试试这个匹配字符串。
DECLARE @temp1 VARCHAR(1000)
SET @temp1 = '<li>Error in connecting server.</li>'
DECLARE @temp2 VARCHAR(1000)
SET @temp2 = '<li>Error in connecting server. connection timeout.</li>'
IF @temp1 like '%Error in connecting server.%' OR @temp1 like '%Error in connecting server. connection timeout.%'
SELECT 'yes'
ELSE
SELECT 'no'