回答
假設你有一個包含一個表位置列表(例如locations (name varchar(100))
),你可以這樣做:
select name from locations where @input like '%'+name+'%'
哪裏@input
是你輸入的字符串(「巴黎時裝更新」等)。
順便說一句,如果您正在使用SQL Server,這裏是一招得到一個字符串輸出沒有while
循環:
select @output = @output + ' ' + name
from locations where @input like '%'+name+'%'
謝謝 - 但是如果我的字符串包含多個位置可能是像'巴黎和倫敦時尚週' – user467710
@ user467710它將工作:檢查出來:http://sqlfiddle.com/#!3/e21586/1 – Blorgbeard
是的,我有一個表與預定義的位置表 – user467710
與預定義位置創建一個表:
CREATE TABLE locations
(
[name] VARCHAR(50)
);
INSERT INTO locations
([name])
VALUES ('Paris'),
('Las Vegas'),
('London');
CREATE TABLE [test]
(
[input] VARCHAR(max)
)
INSERT INTO [test]
(input)
VALUES ('Las Vegas parties at weekends'),
('Paris fashion updates'),
('Paris and London fashion weeks')
然後與輸入字符串表加入吧:
SELECT
t.Input,
l.Name
FROM
Locations AS l
INNER JOIN test AS t ON t.Input LIKE '%' + l.Name + '%'
ORDER BY
t.Input
這裏的SQL Fiddle。
- 1. 從字符串中提取SQL參數名稱
- 2. RegEx在字符串中找到字符串後提取名稱
- 3. 從字符串中提取數字和名稱
- 4. 從字符串中提取數字和名稱[r]
- 5. 從Ruby中的字符串中提取月份名稱
- 6. 從字符串中提取數據sql
- 7. SQL從字符串中提取值
- 8. Javascript:從字符串中提取不同位置的數字?
- 9. 從字符串中提取數字(4個位置)
- 10. 基於sql server中索引位置的字符串提取
- 11. 如何從字符串數組中提取名稱屬性?
- 12. 如何從一組字符串中提取產品名稱? (php)
- 13. 從連接字符串中提取機器名稱
- 14. 從數據庫中提取方法名稱的字符串?
- 15. JavaScript從字符串中提取值 - 股票和公司名稱
- 16. 任何方式從字符串值中提取變量名稱?
- 17. 用紅寶石從字符串中提取城市名稱
- 18. 從字符串中提取業務名稱和時間段
- 19. 從字符串中提取字符串
- 20. 提取列名和表名從任何「SQL查詢」字符串
- 21. 獲取名稱(字符串)
- 22. 從字符串中提取
- 23. 從字符串中提取
- 24. 提取號碼從字符串SQL
- 25. 從SQL提取日期字符串
- 26. SQL:從字符串提取日期
- 27. Pervasive SQL - 獲取字符串中字符的位置
- 28. 從字符串名稱
- 29. 提取名稱,並從字符串的正則表達式
- 30. 從sql字符串獲取表名
你有一個包含預定義位置的表嗎? –
@AlexFilipovici:+1;如果沒有參考表,我懷疑這樣的事情是不可能的! XD – AKDADEVIL
哦,等等:用** RegEx **尋找以大寫字母開頭的單詞(至少可以用於英語字符串),可能會有一種非常混亂的方式,但它會非常容易出錯...... – AKDADEVIL