在参数变量上使用Like?

Con*_*eak 0 sql t-sql sql-server-2008

Select Column1 From Table Where @Variable Like '%' + Column2 + '%'
Run Code Online (Sandbox Code Playgroud)

似乎没有工作我的想法.有什么建议?

why*_*heq 6

(模糊的问题)

你是否以错误的方式得到了Category和@Variable: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 + '%' 
Run Code Online (Sandbox Code Playgroud)