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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trouble with the LIKE statement

Author  Topic 

hwdev
Starting Member

17 Posts

Posted - 2005-04-04 : 21:37:15
I am passing in @Last_Name and when I execute my stored procedure thru the command line (exec memberlisting "DE%") I get 0 rows returned.
(Ex: Where tbl.Mbr_name Like @Last_Name) But when I hard code my where clause (Where tbl.Mbr_name Like "DE%") I get several rows back. I displayed @last_name right before my select statement and it shows DE% like it should.

Is there such a thing as a setting at the server level to allow for wild card

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-04-04 : 22:49:05
Can you post the code?

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

hwdev
Starting Member

17 Posts

Posted - 2005-04-04 : 22:51:55
I did a little more research and discovered my problem.

I had my input parameter defined as Char and the table definition for last/first name is VarChar. I changed the input to be VarChar and it works, I am not sure I totally understand why but it works now.
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-04-04 : 22:58:36
Either you were cutting off the percent, or it was searching for blank spaces after the % sign. If you did an RTRIM, it might have worked for you. In the long run, you're better off having it as VARCHAR though for this type of query.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Ravi Varma
Starting Member

2 Posts

Posted - 2005-04-05 : 01:16:30
Varchar:
Go to Top of Page

Ravi Varma
Starting Member

2 Posts

Posted - 2005-04-05 : 01:18:53
Sorry for the previous post, I pressed a wrong enter to submit some how..
Varchar:
Where @LastName Like "DE%" works fine
But for Char:
Where @LastName Like "DE%%%" will work (If the length of the Char is 5)
Go to Top of Page
   

- Advertisement -