select * from dbo.Tab_UserMainRecord where chrTradeID=case intUserID when 1000001 then '11' else '12' end and intUserID=1000001 用于验证intUserID记录的chrUserID是否为‘11’的例子,也许对您有所帮助
同意四非兄。其实很多问题的解决可以考虑从其他的路径走。 比如这个问题的if else then我觉得肯定可以用where ((..and ..) or (..and..))这样的句法完成。
where (intUserID=1000001 and chrTradeID='11') or(intUserID<>1000001 and chrTradeID='12' )
sql语句中的分支条件表达式应该返有一个返回值,因此它不限于where之后。 方法一可以采用DECODE函数。 zag(急弯) 的写法应该是成立的,不过我不知道你在oracle的哪个版本上测试过没有? 资料上介绍SQL中可以使用CASE WHEN 条件1 THEN 返回值1 ELSE 返回值N END 但是我在815上使用时报错 ORA-00923: 未找到预期 FROM 关键字
ORACLE中根本没有CASE WHEN这样的语法,用DECODE
我试了一下: select * from t_bill where (case when famount>0 then 1 else -1 end)=1 完全可以。 不过这样写真没什么必要,写成: select * from t_bill where famount>0 不是简单得多?想不出来什么情况下一定要在where 中用case when else .
Sample: select distinct publication.description, issue.issue_no, issue.pubdate from publication, issue where publication.publication = issue.publication and substring(issue.issue_no,3,1) >= case when @thirdchar > '9' then @thirdchar else '0' end and substring(issue.issue_no,3,1) <= case when @thirdchar > '9' then @thirdchar else '9' end and @issue1 <= case when convert(integer,substring(issue_no,1,2)) < 50 then '20' + issue_no else '19'+ issue_no end and @issue2 >= case when convert(integer,substring(issue_no,1,2)) < 50 then '20' + issue_no else '19'+ issue_no end order by publication.description, issue.issue_no
用于验证intUserID记录的chrUserID是否为‘11’的例子,也许对您有所帮助
比如这个问题的if else then我觉得肯定可以用where ((..and ..) or (..and..))这样的句法完成。
or(intUserID<>1000001 and chrTradeID='12' )
方法一可以采用DECODE函数。
zag(急弯) 的写法应该是成立的,不过我不知道你在oracle的哪个版本上测试过没有?
资料上介绍SQL中可以使用CASE WHEN 条件1 THEN 返回值1 ELSE 返回值N END
但是我在815上使用时报错
ORA-00923: 未找到预期 FROM 关键字
select *
from t_bill
where (case when famount>0 then 1 else -1 end)=1
完全可以。
不过这样写真没什么必要,写成:
select * from t_bill where famount>0 不是简单得多?想不出来什么情况下一定要在where 中用case when else .
select distinct publication.description,
issue.issue_no,
issue.pubdate
from publication, issue
where publication.publication = issue.publication
and substring(issue.issue_no,3,1) >= case
when @thirdchar > '9' then @thirdchar
else '0'
end
and substring(issue.issue_no,3,1) <= case
when @thirdchar > '9' then @thirdchar
else '9'
end
and @issue1 <= case
when convert(integer,substring(issue_no,1,2)) < 50 then
'20' + issue_no
else '19'+ issue_no
end
and @issue2 >= case
when convert(integer,substring(issue_no,1,2)) < 50 then
'20' + issue_no
else '19'+ issue_no
end
order by publication.description, issue.issue_no