turtle
turtle

Reputation: 8073

SQLite query to match text string in column

I have a database column that contains text in CSV format. A sample cell looks like this:

Audi,Ford,Chevy,BMW,Toyota

I'd like to generate a query that matches any column with the string 'BMW'. How can I do this in SQL?

Upvotes: 8

Views: 51396

Answers (4)

Marimuthu Kandasamy
Marimuthu Kandasamy

Reputation: 516

Another Way...

--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

Upvotes: 1

Vishal Suthar
Vishal Suthar

Reputation: 17193

You can use wildcard characters: %

select * from table 
where name like '%BMW%'

Upvotes: 25

Xavjer
Xavjer

Reputation: 9226

I think you are looking for something like

SELECT * FROM Table
WHERE Column LIKE '%BMW%'

the % are wildcards for the LIKE statement.

More information can be found HERE

Upvotes: 5

Arif YILMAZ
Arif YILMAZ

Reputation: 5866

select * from table where name like '%BMW%'

Upvotes: 2

Related Questions