Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个看起来像这样的查询:
select * from Table1 where name like '%ASD%'
我想改变它,以便我可以做这样的事情:
declare @name1 varchar(255) select @name1 = 'dfg' select * from Table1 where name like @name1
我应该如何做到这一点?
尝试:
SELECT * FROM Table1 WHERE name LIKE '%' + @name1 + '%'
而SET @name1 = 'dfg'不是SELECT @name1 = 'dfg'
SET @name1 = 'dfg'
SELECT @name1 = 'dfg'
用于SET为 分配一个值@name1,并确保将其设置为所需的搜索字符串(您通常将其视为以百分号开头、以一个结尾或两者兼有):
SET
@name1
set @name1 = '%dfg%'