在参数变量上使用 Like ? [英] Using Like on a Parameter Variable?

查看:29
本文介绍了在参数变量上使用 Like ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Select Column1 From Table Where @Variable Like '%' + Column2 + '%'

似乎不像我想象的那样工作.有什么建议吗?

Doesn't seem to work how I thought it would. Any suggestions?

推荐答案

(含糊不清的问题)

您是否以错误的方式获得了 Category 和 @Variable:sqlFiddle

Have you got Category and @Variable round the wrong way: sqlFiddle

create table the_table 
(
  category varchar(10),
  [Date] datetime,
  Amount decimal(12, 2)
)

insert into the_table
values
( 'X', '2012-1-1', 10),
( 'X', '2012-1-3', 10),
( 'Y', '2012-1-3', 20),
( 'Y', '2012-1-5', 10)

declare @Variable varchar(10)
set @Variable = 'Y'

Select * 
From the_table 
--Where @Variable Like '%' + category + '%' 
Where category Like '%' + @Variable + '%' 

这篇关于在参数变量上使用 Like ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆