如果查询中需要包含*号该如何处理,我要查询的是字符串中包含 53*1.0*5.8 的所有记录
语句如下
SELECT *
FROM tb
where contains(ResourceDesc,'53*1.0*5.8')
返回结果如下焊管/ Q195--Q235/ 53*1.0*5.8/ 天津市华海通钢铁有限公司/ 4660/ 88.00/ 天津市/ 2012-2-19/ 焊管/ Q195--Q235/ 53*1.7*5.8/ 天津市市华海通钢铁有限公司/ 4500/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.0*9/ 天津市华海通钢铁有限公司/ 4660/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.0*9/ 天津市华海通钢铁有限公司/ 4660/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.2*9/ 天津市华海通钢铁有限公司/ 4620/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.3*9/ 天津市华海通钢铁有限公司/ 4590/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.5*9/ 天津市华海通钢铁有限公司/ 4540/ 88.00/ 天津市/ 2012-2-19/
其中只有红色的是我需要的使用语句
SELECT *
FROM [CRM_Customer].[dbo].[CustomerInfoPoolItem]
where contains(ResourceDesc,'"53*1.0*5.8"')也是一样的结果
求助
语句如下
SELECT *
FROM tb
where contains(ResourceDesc,'53*1.0*5.8')
返回结果如下焊管/ Q195--Q235/ 53*1.0*5.8/ 天津市华海通钢铁有限公司/ 4660/ 88.00/ 天津市/ 2012-2-19/ 焊管/ Q195--Q235/ 53*1.7*5.8/ 天津市市华海通钢铁有限公司/ 4500/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.0*9/ 天津市华海通钢铁有限公司/ 4660/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.0*9/ 天津市华海通钢铁有限公司/ 4660/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.2*9/ 天津市华海通钢铁有限公司/ 4620/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.3*9/ 天津市华海通钢铁有限公司/ 4590/ 88.00/ 天津市/ 2012-2-19/
焊管/ Q195--Q235/ 53*1.5*9/ 天津市华海通钢铁有限公司/ 4540/ 88.00/ 天津市/ 2012-2-19/
其中只有红色的是我需要的使用语句
SELECT *
FROM [CRM_Customer].[dbo].[CustomerInfoPoolItem]
where contains(ResourceDesc,'"53*1.0*5.8"')也是一样的结果
求助
SELECT *
FROM tb
where freetext(ResourceDesc,'53*1.0*5.8')
FROM tb
where ResourceDesc like '%53/*1.0/*5.8' escape'/'
FROM tb
where ResourceDesc like '%53/*1.0/*5.8%' escape'/'
SQLServer联机帮助帮助里面将contains和fulltext函数都提到过
如下:
使用 FREETEXT 谓词
使用 FREETEXT 谓词可以输入单词或短语的任意集合,甚至一个完整的句子。全文查询引擎将检查该文本,标识出所有重要的单词和名词短语,并用这些条件在内部构造一个查询。此例使用 FREETEXT 谓词查询名为 description 的一列。
FREETEXT (description, ' "The Fulton County Grand Jury said Friday an investigation 下面来自联机帮助关于全文索引的实例,用于pub数据库:
USE pubs
-- Create and populate a table.
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'FulltextTest ')
DROP TABLE FulltextTest
GO
CREATE TABLE FulltextTest
( article_id int IDENTITY(100,1)
CONSTRAINT PK_title_id PRIMARY KEY,
article_title nvarchar(200)
)
GO
INSERT FulltextTest (article_title) VALUES (N 'Steven Buchanan has always enjoyed ice skating. ')
INSERT FulltextTest (article_title) VALUES (N 'Elvis Stoiko: The best male figure skater ')
INSERT FulltextTest (article_title) VALUES (N 'Steven Buchanan On Ice: Skating Reaches Tops in Public Opinion Poll ')
INSERT FulltextTest (article_title) VALUES (N 'Last night, Steven Buchanan skated on the ice!! Skating fans cheer! ')
INSERT FulltextTest (article_title) VALUES (N 'Ice-skating brings out the best in Steven. Buchanan exults in first victory... ')
GO -- Enable full-text searching in the database.
EXEC sp_fulltext_database 'enable '
GO -- Create a new full-text catalog.
EXEC sp_fulltext_catalog 'StevenBCatalog ',
'create '
GO -- Register the new table and column within it for full-text querying,
-- then activate the table.
EXEC sp_fulltext_table 'FulltextTest ',
'create ',
'StevenBCatalog ',
'PK_title_id '
EXEC sp_fulltext_column 'FulltextTest ',
'article_title ',
'add '
EXEC sp_fulltext_table 'FulltextTest ',
'activate '
GO -- Start full population of the full-text catalog. Note that it is
-- asynchronous, so delay must be built in if populating a
-- large index. EXEC sp_fulltext_catalog 'StevenBCatalog ',
'start_full '
-- Execute a full-text query against the new table.
SELECT article_title
FROM FulltextTest
WHERE CONTAINS(article_title, ' "Steven Buchanan " AND "ice skating " ') 帮助上说会最后显示:
article_title
------------------------------------------------------------------------
Steven Buchanan has always enjoyed ice skating.
Last night, Steven Buchanan skated on the ice!! Skating fans cheer!
Steven Buchanan On Ice: Skating Reaches Tops in Public Opinion Poll
Ice-skating brings out the best in Steven. Buchanan exults in first victory...
(4 row(s) affected)
SELECT *
FROM tb
where ResourceDesc like '%53/*1.0/*5.8%' escape'/'