有列的表:number1,number2,number3
在程序中有查询:SELECT number1,number2,number3 FROM myTbl
,现在要检查
if number2 < number1 and number1 < number3 print 'OK'`
怎么做?我不能为它写选择
有列的表:number1,number2,number3
在程序中有查询:SELECT number1,number2,number3 FROM myTbl
,现在要检查
if number2 < number1 and number1 < number3 print 'OK'`
怎么做?我不能为它写选择
如果您需要选择:
SELECT number1, number2, number3
FROM YourTable
WHERE
number2 < number1
AND number1 < number3
或者
SELECT
number1, number2, number3,
CASE WHEN number2 < number1 AND number1 < number3 THEN 'OK' ELSE '' END AS Res
FROM YourTable
问题有点不清楚,但如果你想有条件打印,试试这个
if exists (SELECT * FROM myTbl where number2 < number1 and number1 < number3)
print 'Ok'
像这样的东西?
declare @test int;
select @test = case when number2<number1 and number1<number3 then 1 else 0 end
from test1 where id=3;
if @test = 1 then print 'OK'
我想你想要这个
if @number2 < @number1 and @number1 < @number3
Begin
Print 'OK'
End
或这个
Select CASE WHEN ( @number2 < @number1 and @number1 < @number3THEN expression1)
Then 'OK' Else '' End
我认为:
DECLARE @number1 int
DECLARE @number2 int
DECLARE @number3 int
SELECT
@number1 = number1,
@number2 = number2,
@number3 = number3
FROM myTbl
WHERE (some condition to get only row)
IF (@number2 < @number1 and @number1 < @number3)
BEGIN
print 'OK'
END
declare @ID int = '' --im assuming you have some sort of ID and multiple rows in the table
declare @num1 int = (select number1 from mytable where [ID] = @ID)
declare @num2 int = (select number2 from mytable where [ID] = @ID)
declare @num3 int = (select number2 from mytable where [ID] = @ID)
IF @num2 < @num1 AND @num1 < @num3
begin
SELECT 'OK'
PRINT 'OK'
end
ELSE
begin
SELECT'OK'
PRINT 'OK'
END