1
Select * from MyTable 
    where myField = 1
    And myImportantField ???
    ...

我有以下参数:

@DoCalculateValues bit,  
@FromValue int,  
@ToValue int  

我需要这个

if @DoCalculateValues = 1 then  
check if myImportantField is between @FromValue and @ToValue  
else  
ignore values, something like "And myImportantValue = myImportantValue"

请考虑这一切都发生在“... WHERE ... AND ...”子句的中间

4

2 回答 2

3
Select * from MyTable 
where myField = 1
And (@DoCalculateValues = 0
or myImportantField between @FromValue and @ToValue)
于 2012-07-24T08:56:36.367 回答
0
Select * from MyTable  
where myField = 1 
And ((myImportantField between @FromValue and @ToValue and @DoCalculateValues = 1)
OR  ( @DoCalculateValues <> 1))
于 2012-07-24T08:55:31.157 回答