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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

charindex incorrect

Status
Not open for further replies.

morechocolate

Technical User
Apr 5, 2001
225
US
using the statement charindex(PHIST.LOAN, p.loan_name)}

and given

phist.loan = 111111
p.loan_name = property name 111111

would return 15

but

phist.loan = 222222
p.loan_name = property name 222222 (other text)

would return 0 even though the loan is within the loan_name

I cannot figure this out to save my life
 
works here
Code:
declare @LOAN varchar(30)
declare @LOANname varchar(130)
select @LOAN = '111111'
select @LOANname ='property name 111111'

select charindex(@LOAN, @LOANname)

GO

declare @LOAN varchar(30)
declare @LOANname varchar(130)
select @LOAN = '222222'
select @LOANname ='property name 222222 (other text)'

select charindex(@LOAN, @LOANname)
GO

Denis The SQL Menace
SQL blog:
Personal Blog:
 
SQLDenis when I put in what you provided above it works,

but when I do the following

select charindex(p.loan,rtrim(substring(p.loan_name,1,charindex('(',p.loan_name)-1)))
from lmast p
where p.loan = '3333333'

and p.loan_name = PROP NAME 3333333 (NOTE F)

it returns 0

same thing if I do

select charindex(p.loan,,p.loan_name)
from lmast p
where p.loan = '3333333'

but, if I replace p.loan with '3333333' I get the correct results

see - weird
 
I know where you were going and was hoping they would have been different, but they were the same results.
 
Even this works for me, same code you have
declare @LOAN varchar(30)
declare @LOANname varchar(130)
select @LOAN = '222222'
select @LOANname ='property name 222222 (other text)'

select charindex(@LOAN,rtrim(substring(@LOANname,1,charindex('(',@LOANname)-1)))

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Lord I hate stupid issues. SQLDenis I finally figured it out. BTW - I put in editplus and did not see any hidden characters, but I decided to try something. Eventhough the len test showed the length to be equal I said why not just do a rtrim on p.loan. Guess what? That worked. UGH!!! I spent hours just to come to that!!!

Thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top