Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL query problem

Author  Topic 

webwiredit
Starting Member

5 Posts

Posted - 2009-09-29 : 13:04:04
Hi everyone... I am having issues with my query... It doesn't give me any results, no matter what I put in... What am I doing wrong?


Select * FROM CRM_Contacts WHERE
(BusinessName LIKE '%' + @SearchParameter + '%' OR
PrimaryContactFirstName LIKE '%' + @SearchParameter + '%' OR
PrimaryContactLastName LIKE '%' + @SearchParameter + '%' OR
SecondaryContactFirstName LIKE '%' + @SearchParameter + '%' OR
SecondaryContactLastName LIKE '%' + @SearchParameter + '%')

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-29 : 13:15:14
that means there's no records having @SearchParameter value in any of the fields
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-29 : 13:15:54
Maybe your @SearchParameter is null?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-09-29 : 13:20:09
I'm not seeing anything wrong with your syntax. Could you give an example of a searchparameter that you have verified can be found in the CRM_Contacts table? I assume the data types are all varchar.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

webwiredit
Starting Member

5 Posts

Posted - 2009-09-29 : 14:22:05
@visakh16, no, there are plenty of records

@webfred, when I step through, SearchParameter does have value

@jimf, Sure, there are 3 records of PrimaryContactFirstName, Jan, Michael, and Luke ... searching for "a" alone should return Jan and Michael, but I have even tried searching for them directly by their names... No results ... Yes, all datatypes are nvarchar (50)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-29 : 14:42:09
And your query goes on CRM_Contacts in the right database?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -