Can I put like expression into SQL statement like this?
select @Count = SUM(cast(Value as int))
from tTag
where Name like '[Car],[Truck],[Bike]'
If you are searching for whole words use:
where Name = 'Car' or Name = 'Truck' or Name = 'Bike' --or
where Name = '[Car]' or Name = '[Truck]' or Name = '[Bike]' --or
where Name in ('Car', 'Truck', 'Bike') --or
where Name in ('[Car]', '[Truck]', '[Bike]')
If you are searching as parts of words then use:
where Name like '%Car%' or Name like '%Truck%' or Name like '%Bike%'
But if you are searching for strings like some text [car] some text then this won't work:
where Name like '%[Car]%' or Name like '%[Truck]%' or Name like '%[Bike]%'
because %[Car]% this will match for example some text ca some text. You should escape [ and ] symbols. But it depends on database engine. For example for Sql Server:
where Name like '%\[Car\]%' ESCAPE '\' or
Name like '%\[Truck\]%' ESCAPE '\' or
Name like '%\[Bike\]%' ESCAPE '\'
Select @Count = SUM(cast(Value as int)) from tTag
where Name like '[Car]' or Name like '[Truck]' or name like '[Bike]'
sql-serverandtsqltags based on the non-standard syntax