一个sql查询

jxzhang615 2006-08-11 01:32:10
tablename:A
表结构如下

f1 f2 f3
a b c
d e f
g h i


我想实现 如果 f1的内容是%号是查询结果是全部内容,否则就是where f1='a'

slect form A where f1='a'
...全文
204 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxzhang615 2006-08-11
  • 打赏
  • 举报
回复
谢谢各位
fcuandy 2006-08-11
  • 打赏
  • 举报
回复
学习.
abc_sk 2006-08-11
  • 打赏
  • 举报
回复
select * from A where f1=(case f1 when '%' then f1 else 'a' end)
QQMagicer 2006-08-11
  • 打赏
  • 举报
回复
@f1可以作为传入的参数
if (@f1 ='%')
select * from A
else
select * from A
where f1='a'

子陌红尘 2006-08-11
  • 打赏
  • 举报
回复
declare @f1 varchar(10)
set @f1='%'
select * from A where f1=(case @f1 when '%' then f1 else 'a' end)
子陌红尘 2006-08-11
  • 打赏
  • 举报
回复
declare @f1 varchar(10)
set @f1='%' --'a'

select form A where f1 like @f1

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧