if 语句和mysql select if语句语句

sql语句中使用if包含三个及以上条件
经验值 & | &F豆 600 个 &| &F币 1 元
最佳答案 0 条 &| &最后登录
我在设置查询条件的时候遇到在下拉列表中有三个选择,分别为A,B,C,所以我要在sql语句中使用if,但是在FineReport中if的用法好像只能是if(条件,结果1,结果2),我是想问有没有办法可以像Oracle中的decode用法一样,可以是if(条件1,结果1,条件2,结果2,。。。),类似于if...else if....else这种用法,还请大神指点。。。。
此贴共有 88 位番薯登陆后查看
width:100%">
经验值 & | &F豆 600 个 &| &F币 1 元
最佳答案 0 条 &| &最后登录
<font color="#34569 发表于
IF中可以继续镶嵌IF的,同样可以达到你的要求。
你的意思是这样写:${if(para=0,' and ConditionA=1',if(para=1,' and ConditionB=1',if(para=2,' and COnditionC=1')))}?
width:100%">
经验值 & | &F豆 600 个 &| &F币 1 元
最佳答案 0 条 &| &最后登录
恩,已经可以了。谢谢各位了!~~~
width:100%">
经验值 & | &F豆 1955 个 &| &F币 38 元
最佳答案 1 条 &| &最后登录
IF中可以继续镶嵌IF的,同样可以达到你的要求。
width:100%">
经验值 & | &F豆 600 个 &| &F币 1 元
最佳答案 0 条 &| &最后登录
你的意思是这样写:${if(para=0,' and ConditionA=1',if(para=1,' and ConditionB=1',if(para=2,' and COnditionC=1')))}?
width:100%">
经验值 & | &F豆 24954 个 &| &F币 136 元
最佳答案 13 条 &| &最后登录
懒人 发表于
你的意思是这样写:${if(para=0,' and ConditionA=1',if(para=1,' and ConditionB=1',if(para=2,' and COnd ...
正解,在sql加入参数
width:100%">
经验值 & | &F豆 5018 个 &| &F币 21 元
最佳答案 10 条 &| &最后登录
也可以用switch公式
width:100%">
经验值 & | &F豆 2014 个 &| &F币 1 元
最佳答案 9 条 &| &最后登录
用IF可以。
width:100%">
经验值 & | &F豆 12409 个 &| &F币 21 元
最佳答案 52 条 &| &最后登录
参数可以是任意字符串,因为最后参数是最为一整个字符串和原先的拼接在一起让数据库服务器执行的,只要最后的语句符合语法,能让数据库执行就可以了
width:100%">
经验值 & | &F豆 1955 个 &| &F币 38 元
最佳答案 1 条 &| &最后登录
懒人 发表于
你的意思是这样写:${if(para=0,' and ConditionA=1',if(para=1,' and ConditionB=1',if(para=2,' and COnd ...
可以~~~~~~~~~~~
width:100%">
Fineres Certified Reporting Associate
帆软认证报表工程师
V8.0测试勋章
V8.0“一个BUG一百块”活动纪念勋章
V8.0体验勋章
在V8.0体验活动中提出了宝贵建议
在帆软论坛做出了突出贡献的人,会被授予荣誉勋章
当他回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞耻,他已经把他的整个生命和全部精力,都献给了帆软论坛
传说哥推荐
FineReport
Copyright & 帆软(中国)软件有限公司|21444人阅读
数据库SQL SERVER(42)
SQL 流程控制语句 之一& IF&ELSE语句
有表 publishers&& 如下图:
执行IF&ELSE语句:
declare @a int,@b varchar(100)
set @a=(select count(titles_id) from titles);
set @b=convert(varchar(100),@a);
&&&& select @a+1 as a
&&&& begin
&&&&&&&&& select @b+'2' as b
&&&&&& && select 900
得出结果如下:
你们说这个结果 执行上if& 还是 else&?& 另外告诉大家 begin...end之间的东西被看做一个整体语句块相当一个语句.我如果再执行一个程序如下:
declare @a int,@b varchar(100)
set @a=(select count(titles_id) from titles);
set @b=convert(varchar(100),@a);
&&&& select @a+1 as a
&&&& begin
&&&&&&&&& select @b+'2' as b
&&&&&& && select 900
得出结果如下图:
大家明白了吧! 既然明白了,就要讲 if...else 的理论知识了! 等一下我梳个头 带个眼镜 再拿一本大部头&& 睡死你!
一、流程控制语句
流程控制语句是指那些用来控制程序执行和流程分支的命令,在SQL Server 2000中,流程控制语句主要用来控制SQL语句、语句块或者存储过程的执行流程。
<font color="#.IF&ELSE语句
<font color="#.BEGIN&END语句
<font color="#. WHILE&CONTINUE&BREAK语句&&
<font color="#. WAITFOR语句
<font color="#. RETURN语句
二、 IF&ELSE语句
IF&ELSE语句是条件判断语句,其中,ELSE子句是可选的,最简单的IF语句没有ELSE子句部分。IF&ELSE语句用来判断当某一条件成立时执行某段程序,条件不成立时执行另一段程序。SQL Server允许嵌套使用IF&ELSE语句,而且嵌套层数没有限制。
三、IF&ELSE语句的语法形式
IF Boolean_expression &&&&&& { sql_statement | statement_block }
[ ELSE &&&&&& { sql_statement | statement_block }
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:317115次
积分:3898
积分:3898
排名:第6515名
原创:76篇
转载:59篇
评论:36条
(2)(1)(3)(1)(2)(1)(9)(1)(3)(2)(5)(4)(3)(8)(17)(33)(1)(39)74801人阅读
IF语句的使用A.基本的IF条件语句:基本语法:
IF THEN&&END IF;
SQL&SQL& declare && x number(3):=9;&&&&begin&&&&if x&10 then&&&&dbms_output.put_line('x is less than10');&&&&&&&& /
结果:x is less than10PL/SQL procedure successfully completedB.IF - ELSE 语句基本语法:
IF THEN&&ELSE&&END IF;
DECLAREx NUMBER(3) := 10; BEGIN&&IF x & 10 THEN&&&&dbms_output.put_line('X is less than 10');&&ELSE&&&&dbms_output.put_line('X is not less than 10');&&END IF;END;/
结果:X is not less than 10PL/SQL procedure successfully completedC:IF - ELSIF - ELSE 语句基本语法:
IF THEN&&ELSIF THEN&&ELSIF THEN&&ELSE&&END IF;
set serveroutput onDECLAREx NUMBER(3) := 47; BEGIN&&IF x & 10 THEN&&&&dbms_output.put_line('X is less than 10');&&ELSIF x = 10 THEN&&&&dbms_output.put_line('X is equal to 10');&&ELSIF x & 100 THEN&&&&dbms_output.put_line('X is between 11 and 99');&&ELSE&&&&dbms_output.put_line('X is greater than 99');&&END IF;END;/
结果:X is between 11 and 99PL/SQL procedure successfully completedD:与NULL值比较处理Example:
declare&&&&&& v NUMBER;&& begin&&&&&& if v = 1 then&&&&&&&&&& DBMS_OUTPUT.put_line('Equal to 1');&&&&&& elsif v!= 1 then&&&&&&&&&& DBMS_OUTPUT.put_line('Not equal to 1');&&&&&& elsif v = v then&&&&&&&&&& DBMS_OUTPUT.put_line('Equal to itself');&&&&&& else&&&&&&&&&& DBMS_OUTPUT.put_line('Undefined result');&&&&&&&&&&&& v:=v+1;&&&&&& DBMS_OUTPUT.put_line('New value: &'||v||'&');&&/
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:191358次
积分:1366
积分:1366
排名:千里之外
原创:13篇
转载:37篇
(2)(4)(3)(1)(9)(2)(2)(1)(1)(1)(2)(2)(8)(1)(5)(3)(2)(1)selectUNITNAME,WRITER,PH;(if(MPOSTSisnull,0,MPOST;M_Persont,T_Persont,L_Pe;ML3,ML4,ML5,ML6,ML7,ML8,;HL,ML,LL,;TL2,TL3,TL4,TL5,TL6,TL7,;LL3,LL4,LL5,LL14,;cast(MRATIOaschar)asMYMR;MP
selectUNITNAME,WRITER,PHONE,Real_Person_Num,
(if(MPOSTS is null,0,MPOSTS)+if(TPOSTS is null,0,TPOSTS)+if(WPOSTS is null,0,WPOSTS)) as TOTAL_POSTS,
M_Persont,T_Persont,L_Persont,
ML3,ML4,ML5,ML6,ML7,ML8,ML9,ML10,
TL2,TL3,TL4,TL5,TL6,TL7,TL8,TL9,TL10,TL11,TL12,TL13,
LL3,LL4,LL5,LL14,
cast(MRATIO as char) as MYMRATIO,cast(TRATIO as char) as MYTRATIO,cast(WRATIO as char) as MYWRATIO,
MPOSTS,TPOSTS,WPOSTS,
if(cast(round(ROUND(ML3/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML3/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mbl3,
if(cast(round(ROUND(ML4/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML4/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mbl4,
if(cast(round(ROUND(ML5/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML5/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mbl5,
if(cast(round(ROUND(ML6/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML6/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mbl6,
if(cast(round(ROUND(ML7/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML7/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mbl7,
if(cast(round(ROUND(ML8/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML8/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mbl8,
if(cast(round(ROUND(ML9/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML9/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mbl9,
if(cast(round(ROUND(ML10/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML10/if(MPOSTS=0,1,MPOSTS),4)*100,1) as char),&%&)) as mlb10,
if(cast(round(ROUND(HL/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(HL/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as hbl,
if(cast(round(ROUND(ML/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(ML/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as mbl,
if(cast(round(ROUND(LL/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(LL/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as lbl,
if(cast(round(ROUND(TL2/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL2/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl2,
if(cast(round(ROUND(TL3/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL3/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl3,
if(cast(round(ROUND(TL4/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL4/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl4,
if(cast(round(ROUND(TL5/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL5/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl5,
if(cast(round(ROUND(TL5/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL5/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl6,
if(cast(round(ROUND(TL7/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL7/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl7,
if(cast(round(ROUND(TL8/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL8/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl8,
if(cast(round(ROUND(TL9/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL9/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tbl9,
if(cast(round(ROUND(TL10/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL10/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tlb10,
if(cast(round(ROUND(TL11/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL11/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tlb11,
if(cast(round(ROUND(TL12/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL12/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tlb12,
if(cast(round(ROUND(TL13/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(TL13/if(TPOSTS=0,1,TPOSTS),4)*100,1) as char),&%&)) as tlb13,
if(cast(round(ROUND(LL3/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(LL3/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char),&%&)) as wlb3,
if(cast(round(ROUND(LL4/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(LL4/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char),&%&)) as wlb4,
if(cast(round(ROUND(LL5/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(LL5/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char),&%&))
if(cast(round(ROUND(LL14/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char)=&0.0&,&&,concat(cast(round(ROUND(LL14/if(WPOSTS=0,1,WPOSTS),4)*100,1) as char),&%&)) as wlb14
from (SELECT B.UNIT_NAME as UNITNAME,B.WRITER,B.PHONE,B.Real_Person_Num,
if(M_Persont is null,0,M_Persont) as M_Persont,
if(T_Persont is null,0,T_Persont) as T_Persont,
if(L_Persont is null,0,L_Persont) as L_Persont,
if(ML3 is null,0,ML3) as ML3,
if(ML4 is null,0,ML4) as ML4,
if(ML5 is null,0,ML5) as ML5,
if(ML6 is null,0,ML6) as ML6,
if(ML7 is null,0,ML7) as ML7,
if(ML8 is null,0,ML8) as ML8,
if(ML9 is null,0,ML9) as ML9,
if(ML10 is null,0,ML10) as ML10,
if(HL is null,0,HL) as HL,
if(ML is null,0,ML) as ML,
if(LL is null,0,LL) as LL,
if(TL2 is null,0,TL2) as TL2,
if(TL3 is null,0,TL3) as TL3,
if(TL4 is null,0,TL4) as TL4,
if(TL5 is null,0,TL5) as TL5,
if(TL6 is null,0,TL6) as TL6,
if(TL7 is null,0,TL7) as TL7,
if(TL8 is null,0,TL8) as TL8,
if(TL9 is null,0,TL9) as TL9,
if(TL10 is null,0,TL10) as TL10,
if(TL11 is null,0,TL11) as TL11,
if(TL12 is null,0,TL12) as TL12,
if(TL13 is null,0,TL13) as TL13,
if(LL3 is null,0,LL3) as LL3,
if(LL4 is null,0,LL4) as LL4,
if(LL5 is null,0,LL5) as LL5,
if(LL14 is null,0,LL14) as LL14,
if(M_Persont is null,0,M_Persont) as MRATIO,
if(T_Persont is null,0,T_Persont) as TRATIO,
if(L_Persont is null,0,L_Persont) as WRATIO,
if(ML3 is null or length(ML3)=0,0,ML3)+
if(ML4 is null or length(ML4)=0,0,ML4)+
if(ML5 is null or length(ML5)=0,0,ML5)+
if(ML6 is null or length(ML6)=0,0,ML6)+
if(ML7 is null or length(ML7)=0,0,ML7)+
if(ML8 is null or length(ML8)=0,0,ML8)+
if(ML9 is null or length(ML9)=0,0,ML9)+
if(ML10 is null or length(ML10)=0,0,ML10) as MPOSTS,
if(TL2 is null or length(TL2)=0,0,TL2)+
if(TL3 is null or length(TL3)=0,0,TL3)+
if(TL4 is null or length(TL4)=0,0,TL4)+
if(TL5 is null or length(TL5)=0,0,TL5)+
if(TL6 is null or length(TL6)=0,0,TL6)+
if(TL7 is null or length(TL7)=0,0,TL7)+
if(TL8 is null or length(TL8)=0,0,TL8)+
if(TL9 is null or length(TL2)=9,0,TL9)+
if(TL10 is null or length(TL10)=0,0,TL10)+
if(TL11 is null or length(TL11)=0,0,TL11)+
if(TL12 is null or length(TL12)=0,0,TL12)+
if(TL13 is null or length(TL13)=0,0,TL13) as TPOSTS,
if(LL3 is null or length(LL3)=0,0,LL3)+
if(LL4 is null or length(LL4)=0,0,LL4)+
if(LL5 is null or length(LL5)=0,0,LL5)+
if(LL14 is null or length(LL14)=0,0,LL14) as WPOSTS
FROM post_condition A join unit B on A.unit_code=B.unit_code where A.unit_code=$P{unitCode} and A.Is_Extra=&#39;1&#39;)
包含各类专业文献、生活休闲娱乐、文学作品欣赏、专业论文、外语学习资料、幼儿教育、小学教育、98SQL中select中使用if语句案例等内容。 
 在SQL的SELECT语句中,用于实现选择运算的子句是( )。 A) FOR B) IF C) WHILE D) WHERE 正确答案及相关解析
正确答案 D
解析 [解析] SELECT语句的语法...  ( IF 语句、 SELECT 语句) (3)循环结构 程序在运行时会重复执行某一段程序代码 2、IF 语句 (1)单分支选择结构 (2)双分支选择结构 (3)多分支选择结构 行 ...  ASP中SQL语句中SELECT语句的使用_计算机软件及应用_IT/计算机_专业资料。ASP,SELECT语句的使用,ASP中SQL语句中SELECT语句的使用 ASP 中 SQL 语句中 SELECT 语句的...  一、 简单查询 简单的 Transact-SQL 查询只包括选择列表、FROM 子句和 WHERE ...删除重复行 SELECT 语句中使用 ALL 或 DISTINCT 选项来显示表中符合条件的所有...  在SQL的SELECT语句中,用于实现选择运算的是( )。 A.FOR_高考_高中教育_教育专区。一、整体解读试卷紧扣教材和考试说明,从考生熟悉的基础知识入手,多角度、多层次...  VFP 中的 SQL SELECT 语句使用要点_计算机软件及应用_IT/计算机_专业资料。VFP...我举个例子:有二个表: 提货单 thd、提货单明细 thdmx: thd 提货单号 thd...  select 语句 student.sql create table student( id int, name varchar(20), chinese float, english float, math float ); insert into student(id,name,...  在SQL语言的SELECT语句中,用于实现选择运算的子句是___。 A.FOR B.IF C.WHILE D.WHERE 正确答案及相关解析
正确答案 D
解析 [解析] SQL查询的Select语句...  下列语句部分是 Mssql 语句,不可以在 access 中使用...SQL: select a.a, a.b, a.c, b.c, b.d,...end if objRec.MoveNext Wend 这很容易理解。首先,...}

我要回帖

更多关于 select语句做if条件 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信