SQLServer2008 在where条件中使用CASE WHEN
2024-08-24 23:28:56
create table #temp
(
id int identity(1,1),
name varchar(20),
startYear int,
startMonth int
)
insert into #temp
select 'z','2010','12' union all
select 'e','2011','11' union all
select 'a','2011','2' union all
select 'b','2011','5' union all
select 'c','2011','10' union all
select 'd','2011','7'
--查询早于等于指定日期的数据
declare @condition varchar(6)
set @condition='201110'
select * from #temp A
where
(case when LEN(A.startMonth)=1 and A.startMonth!=0 then cast((CAST(startYear as varchar(4))+'0'+cast(A.startMonth as varchar(1))) as date)
when LEN(A.startMonth)=2 then cast(CAST(startYear as varchar(4))+cast(A.startMonth as varchar(2)) as date) end) <=cast(@condition as date)
最新文章
- Spring Boot 添加Shiro支持
- 走进云背后:微软Azure web 项目通过web service部署web site
- Mac SVN 命令行
- 以纯面向对象的JS编写最基本的数据字典案例
- ASP------如何使界面布局具有一致外观
- 乐够GO应用源码完整版
- SQL Server 非聚集索引的覆盖,连接,交叉和过滤 <;第二篇>;
- 去除 waring Method &#39;CreateNew&#39; hides virtual method of base type &#39;TCustomForm&#39;
- 3.8 spring - AbstractBeanDefinition 介绍
- 黑马程序猿 IO流 ByteArrayInputStream与ByteArrayOutputStream
- android 菜单的总结
- Python之MYsql、数据库
- 实用技巧:如何通过IP地址进行精准定位
- OAuth2.0学习(1-9)新浪开放平台微博认证-web应用授权(授权码方式)
- (十分钟视频教程)nodejs基础实战教程3:react服务端渲染入门篇
- const_cast的用法与测试
- Code Signal_练习题_stringsRearrangement
- 使用OpenOffice.org将各类文档转为PDF
- bzoj 2784 [JLOI2012]时间流逝——树上高斯消元
- [2018HN省队集训D6T2] girls
热门文章
- perf-perf stat用户层代码分析
- [forward]警惕UNIX下的LD_PRELOAD环境变量
- STL中队列queue的用法
- 洛谷——P2814 家谱
- 【郑轻邀请赛 B】base64解密
- [bzoj1926][Sdoi2010]粟粟的书架_二分_主席树
- 多校第六场 1003 hdu 5355 Cake(贪心)
- Android 的Recovery机制【转】
- Mac safari&#160;下iframe的hash取不到BUG
- Spring:延迟初始化