case when then...else end sql 语句用法
select f.AGENTID as 'ID',
f.AGENTNAME as '姓名',
f.COMNAME as '公司简称',
c.REGISTDATE as '注册时间',
c.VALIDDATE as '截至时间',
c.DISTRICT as '区县',
c.COMAREA as '负责区域',
c.category as '等级',
case when c.agentcardflag = 1 then '待审核'
when c.agentcardflag = 2 then '审核通过'
when c.agentcardflag = 3 then '未通过'
else '未通过'
end as '身份审核状态'
from MagentInf f ,MagentCon c where c.AGENTID = f.AGENTID and c.Ispay = 0
下面为转载
SELECT
CASE WHEN USERID=10 THEN '社区用户:'+SELECT NAME from(SELECT NAME from USER_INFO UI WHERE UI.[ID]=A.USERID)
WHEN USERID=20 THEN '注册用户:'+SELECT NAME from(SELECT NAME from REGISTER_INFO UI WHERE UI.[ID]=A.USERID)
WHEN UERID=30 THEN '普通用户:'+SELECT NAME from(SELECT NAME from SIMPLE_INFO UI WHERE UI.[ID]=A.USERID)
--.....还有好几个WHEN
ELSE '' END,
A.TITLE,A.TETENT
from BASICINFO A
相关文档:
问题提出:
在应用程序中经常需要查询数据。当查询结果数据量比较大的时候,检索结果、界面显示都需要花费大量的时间。为了避免这个问题,应该每次只检索部分数据,也就是使用常见的分页方式来处理。分页的问题在asp.net中好像非常简单,只要在GridView中启用分页就可以了。启用分页后,GridView关联数据源控件,依旧会加载 ......
declare @CausName as char(20) declare @causenameid as int declare
@Description as varchar(200) declare @Caus_Id as int
declare @sign as char(20)
create table #tb ( Caus_Id int,CausName varchar(20),causNameid int,Caus_Description varchar(200),标志 varchar(20))
DECLARE myCursor1 CURSOR F ......
一、PowerDesigner生成sql问题
生成sql的方法是 Database -->Generate Database (Ctrl + G ) 但是提示
Generation aborted due to errors detected during the verification of the model.
解决方法: 将check model 去掉就可以了.其中,one file on是否需要按照表生成许多个sql(默认选上,即不需要)
& ......
1.使用CTE简化嵌套sql
先看下面一个嵌套的查询语句:
select * from person.StateProvince where CountryRegionCode in
(select CountryRegionCode from person.CountryRegion where  ......