Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHARINDEX, comma, and stored proc ... puzzling ?!? 1

Status
Not open for further replies.

warelock

IS-IT--Management
Aug 16, 2005
12
US
This oen really has me puzzled. I have this code in a stored proc :

BEGIN

DECLARE @BadPattern2 CHAR(10)
DECLARE @BadPattern3 VARCHAR(10)

SELECT @BadPattern2 = '713,'
SET @BadPattern3 = '713'

SELECT ItemExplanationCodes, @BadPattern2 AS BadPattern
FROM BillItemXML
WHERE CHARINDEX( @BadPattern2, ItemExplanationCodes ) != 0

END

This returns no rows.

The funny thing is that if I use @BadPattern3, I find the rows I want. It's as though including the comma prevents CHARINDEX from working ... I don't know why that should be ?

Does anyone know why this is happening ? I'd appreciate help !

Thanks.
 
Change:
DECLARE @BadPattern2 CHAR(10)

TO:
DECLARE @BadPattern2 [!]VarCHAR[/!](10)

Char types are padded with spaces at the end.


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
ooooooo ... that is GOOD.

Thank you once again, gmmastros !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top