0

I want to select some data in sql express by IN clause and LIKE but no row returned. my code is here :

SELECT        PointId, PointTitleId, PointTitleName, PointTitleContentText
FROM          PointsTitlesData
WHERE        (PointTitleContentText LIKE '%' + @SearchingClause + '%') 
             AND (PointId IN ('2','3'))

above code don't return any data but when i use only LIKE code return data.

SELECT        PointId, PointTitleId, PointTitleName, PointTitleContentText
FROM          PointsTitlesData
WHERE        (PointTitleContentText LIKE '%' + @SearchingClause + '%')

how can i use both IN and LIKE? Thanks.

4
  • 1
    are you sure you have records that meet the criteria of the IN? Commented Jul 11, 2012 at 12:06
  • 1
    Well... does the table have any value that is like your search clause and the point id is 2 or 3? Commented Jul 11, 2012 at 12:06
  • Wanna bet that select isn't broken? Commented Jul 11, 2012 at 12:19
  • Can you show us the data from your table where PointId is 2 and 3. Also, table schema for PointsTitlesData table and version of the SQL Server are you using. Commented Jul 11, 2012 at 17:15

2 Answers 2

1

I tried to recreate your scenario with the script below

Declare @SearchingClause nvarchar(20);

Create table PointsTitlesData (Pointid int, PointTitleContentText nvarchar(20));

insert into PointsTitlesData (Pointid, PointTitleContentText)
values ( 1, 'aaamypoint1aaa'), (2, 'bbbmypoint2bbb'),(3,'cccmypoint3ccc');

Set @SearchingClause = 'mypoint2';

SELECT        PointId, PointTitleContentText 
FROM          PointsTitlesData 
WHERE        (PointTitleContentText LIKE '%' + @SearchingClause + '%')  
         AND (PointId IN ('2','3')) 

-- above code don't return any data but when i use only LIKE code return data.

SELECT        PointId, PointTitleContentText 
FROM          PointsTitlesData 
WHERE        (PointTitleContentText LIKE '%' + @SearchingClause + '%') 

I got a result for both queries so it looks like you have a data issue. Have you tried

SELECT PointId from PointsTitlesData where ((PointId = 2) or (PointId = 3))

to check the data is there.

Regards Jude

Sign up to request clarification or add additional context in comments.

Comments

0

probably drop the quotes:

'2','3' should be 2,3

4 Comments

I use 2,3 but no data return yet.
then it must be a data issue. there must be a record that matches both these criteria at the same time
the code is correct. problem is from janus checked combobox. thanks.
@1mohammadi.ir What does "problem is from janus checked combobox" mean? If it is fixed then update or delete the post so people don't spend time trying to answer it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.