惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
V2EX - 技术
V2EX - 技术
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Y
Y Combinator Blog
N
News and Events Feed by Topic
SecWiki News
SecWiki News
U
Unit 42
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Webroot Blog
Webroot Blog
GbyAI
GbyAI
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Vulnerabilities – Threatpost
Vercel News
Vercel News
A
About on SuperTechFans
P
Proofpoint News Feed
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Hacker News: Front Page
云风的 BLOG
云风的 BLOG
Schneier on Security
Schneier on Security
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Palo Alto Networks Blog
Help Net Security
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
L
LangChain Blog
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
aimingoo的专栏
aimingoo的专栏
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
S
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - FilyCks

日期格式化函数 解决日志文件满造成的无法写入问题 数据库的日志文件 Delphi制作DLL SQLSERVER 日期函数及取当天数据 SQL语句导入导出大全 日期数据处理 按时间段统计数据(1) FastReport(5) FastReport(4) FastReport(3) FastReport(2) FastReport(1) 游标嵌套(个人笔记) FastReport 的初学感悟 查询表(个人笔记) 图片转换和读取(个人笔记) 游标的一些例子 自己研究出来的第一个游标
SQL动态条件查询例子
FilyCks · 2009-04-07 · via 博客园 - FilyCks

set nocount on
--数据--------------------------------------------------------------------------

create table [A] ([id] int,[name] varchar(4),[sex] varchar(2))
insert into [A] select 1,'jack','男'
insert into [A] select 2,'Tom','女'
insert into [A] select 3,'jons','女'
insert into [A] select 10,'jfns','女'
go
--条件有:包含,不包含,等于,大于等于,小于等于,不等于,小于,大于等
--代码--------------------------------------------------------------------------
declare @col varchar(10),@t varchar(10),@d varchar(10)
declare @sql varchar(1000)
select @col = 'name',@t = '包含',@d = 'o'
set @sql = 'select * from a where '+rtrim(@col)
+case @t when '包含'    then ' like [email=]''%'+@d+'%'''[/email]
         when '不包含'  then ' not like [email=]''%'+@d+'%'''[/email]
         when '等于'    then [email=]'='''+@d+''''[/email]
         when '不等于'  then '<>'''+@d+''''
         when '大于等于'then '>='''+@d+''''
         when '小于等于'then '<[email==]='''+@d+''''[/email]
         when '小于'    then '<[email==]='''+@d+''''[/email]
         when '大于'    then '<[email==]='''+@d+''''[/email] end
select @col = 'id',@t = '大于等于',@d = '3'
print @sql
exec(@sql)
go
/*结果--------------------------------------------------------------------------
select * from a where name like '%o%'
id          name sex  
----------- ---- ----
2           Tom  女
3           jons 女
select * from a where id>='3'
id          name sex  
----------- ---- ----
3           jons 女
10          jfns 女
--清除------------------------------------------------------------------------*/
drop table a