|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
SQL procedure problem (NOT LIKE '____M')
Hello everyone,
why won't this procedure select everything from Products where the product code's 5th letter is NOT 'M" Code:
ALTER Procedure sp_TextSearchProducts @SearchText varchar(255) AS Select * from Products where (chrProductName like '%' + @SearchText + '%' or txtDescription like '%' + @SearchText + '%' or chrProductCode like '%' + @SearchText + '%' and chrProductCode NOT Like '____M') Order by chrProductName Any Ideas why I am still getting products that have codes ending in M? thanks, Matt |
|
#2
|
||||
|
||||
|
Try this
Code:
SELECT *
FROM Products
WHERE chrProductName like '%' + @SearchText + '%'
OR txtDescription like '%' + @SearchText + '%'
OR
(
chrProductCode like '%' + @SearchText + '%'
AND CHARINDEX('M', chrProductCode) <> 5)
)
|
|
#3
|
||||
|
||||
|
I took what you said and seperated them. I just seperated them like this:
Code:
Select * from Products where ((chrProductName like '%' + @SearchText + '%' or txtDescription like '%' + @SearchText + '%' or chrProductCode like '%' + @SearchText + '%') and chrProductCode NOT Like '____M') I seperated the OR's and the AND since the text could be anything including the product code but its not always the product code. Thanks for the help. Matt |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > SQL procedure problem (NOT LIKE '____M') |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|