SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



Problem with ''Like'' Expand / Collapse
Author
Message
Posted Tuesday, May 24, 2005 5:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 17, 2005 12:20 PM
Points: 9, Visits: 1

Hello,

Here is a part of the query string:

" where VM_PROPERTY.commercialName like '%"+villaName+"%' "+

The query works fine when I put the villa name directly instead of the dynamic string 'villaName'. When I put the 'villaName' string, it's not taken into consideration.

Can you help me with that please

Thank you beforhand

Zineb   

Post #184781
Posted Tuesday, May 24, 2005 5:50 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, February 12, 2008 5:32 AM
Points: 1,758, Visits: 2

Try

'%'+villaName+'%' + instead....





Good Hunting!

AJ Ahrens


webmaster@kritter.net
Post #184785
Posted Tuesday, May 24, 2005 6:22 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
What is villaName? Is it a variable, or a constant string that you want to search for? A columnname?

As always, the best way to solve this kind of problem is to simply output the sql string you are trying to execute before sending it to SQL Server. Then you can easily see if the string is correct syntax or not.




--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #184789
Posted Tuesday, May 24, 2005 6:48 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 17, 2005 12:20 PM
Points: 9, Visits: 1

Thank you for your help.

'%'+villaName+'%' didn't work!

villaName is a string where I put the name of the villa 'palais mehdi' for example.

My query is working in query analyser, but when I put '%"+villaName+"%' in my code, it doesn't give me any error and it doesn't take the villa name into consideration. When I put the name of the villa directly in the query, it's working from the code...I'm confused!

Thank you beforehand

Zineb 

Post #184795
Posted Tuesday, May 24, 2005 4:52 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, February 12, 2008 5:32 AM
Points: 1,758, Visits: 2

Zineb,

What language are you using to code with?  That will help us figure this out with you.





Good Hunting!

AJ Ahrens


webmaster@kritter.net
Post #184979
Posted Tuesday, May 24, 2005 4:55 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
Zineb, please have your code output the sql string that you are executing, right before you execute it. Then post the sql statement here exactly as it is, if you do not immediately spot any error yourself.



--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #184980
Posted Wednesday, May 25, 2005 8:10 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, December 07, 2007 2:42 PM
Points: 80, Visits: 3
To refer to a variable, use @villaname


Post #185109
Posted Wednesday, May 25, 2005 9:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 17, 2005 12:20 PM
Points: 9, Visits: 1

Thank you very much for your trials. I found out that the problem was in a loop I was using in my code. So the synthax '%"+villaName+"%' is right.

Good luck all,

Zineb 

Post #185137
« Prev Topic | Next Topic »


Permissions Expand / Collapse