求问下如何用返回值做为模糊查询的条件
sql吧
全部回复
仅看楼主
level 1
易双&12 楼主
WHERE TH015 LIKE '%202102%'
select convert(varchar(6),getdate(),112)
我是想把条件里的202102,用下面一行语句代替,请问下各位大佬要怎么写?
2021年02月04日 04点02分 1
level 3
试一下
2021年02月04日 05点02分 3
level 3
WHERE TH015 LIKE '%+select convert(varchar(6),getdate(),112)+%'
2021年02月04日 05点02分 4
按这个查出来的是精确查询的返回值。[泪]
2021年02月04日 05点02分
@易双&12 WHERE TH015 LIKE '%'+(select convert(varchar(6),getdate(),112))+'%'
2021年02月04日 09点02分
level 1
易双&12 楼主
感谢,但查询出来的数量和直接用202102查出来的数量对不上。 用你这个查出来的是精确查询的结果 。我需要的是模糊查询的结果。
2021年02月04日 05点02分 5
level 3
可以试试charindex(N'202102',TH015),如果TH015,包括202102,返回1
2021年02月06日 06点02分 6
level 8
WHERE TH015 LIKE '%'+convert(varchar(6),getdate(),112)+'%'
2021年02月20日 00点02分 7
1