qq_25250689 2019-01-11 02:46 采纳率: 50%
浏览 5241
已采纳

sql查询是否包含字符串

如何查询匹配如下的字段值(字符串类型)
能同时查询到:5@1、5@1#6@2、1@1#5@1
不查询:5@12、15@1、

ms sql server表结构数据如下

GO
/****** Object: Table [dbo].[t_test] Script Date: 01/11/2019 02:43:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].t_test NULL
) ON [PRIMARY]
GO
INSERT [dbo].t_test VALUES (N'5@1')
INSERT [dbo].t_test VALUES (N'5@1#6@2')
INSERT [dbo].t_test VALUES (N'1@1#5@1')
INSERT [dbo].t_test VALUES (N'5@12')
INSERT [dbo].t_test VALUES (N'15@1')

  • 写回答

5条回答 默认 最新

  • qq_25250689 2019-01-11 11:23
    关注

    select test,PATINDEX('%5@1%', test) from t_test where PATINDEX('%15@1%', test)=0 and PATINDEX('%15@10%', test)=0 and PATINDEX('%15@11%', test)=0 and PATINDEX('%15@12%', test)=0 and PATINDEX('%15@13%', test)=0 and PATINDEX('%15@14%', test)=0 and PATINDEX('%15@15%', test)=0 and PATINDEX('%15@16%', test)=0 and PATINDEX('%15@17%', test)=0 and PATINDEX('%5@10%', test)=0 and PATINDEX('%5@11%', test)=0 and PATINDEX('%5@12%', test)=0 and PATINDEX('%5@13%', test)=0 and PATINDEX('%5@14%', test)=0 and PATINDEX('%5@15%', test)=0 and PATINDEX('%5@16%', test)=0 and PATINDEX('%5@17%', test)=0

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题