我有一个包含CSV格式文本的数据库列。样本单元格如下所示:
Audi,Ford,Chevy,BMW,Toyota
我想生成一个匹配任何字符串'BMW'的查询。我怎样才能在SQL中执行此操作?
答案 0 :(得分:22)
您可以使用通配符:%
select * from table
where name like '%BMW%'
答案 1 :(得分:4)
答案 2 :(得分:2)
select * from table where name like '%BMW%'
答案 3 :(得分:1)
另一种方式......
--Create Table 2 :
Create Table #Table1
(
Roll_No INT,
Student_Address Varchar(200)
)
Go
-- Insert Values into #Table1:
Insert into #Table1 Values ('1','1st Street')
Insert into #Table1 Values ('2','2rd Street')
Insert into #Table1 Values ('3','3rd Street')
Insert into #Table1 Values ('4','4th Road')
Insert into #Table1 Values ('5','5th Street')
Insert into #Table1 Values ('6','6th Street')
Insert into #Table1 Values ('7','7th Street')
Insert into #Table1 Values ('8','8th Wing')
--Query
Select * from #Table1 where CharIndex('Street',Student_Address) > 0
--Clean Up:
Drop table #Table1