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

How to find a certain letter in a string?

Status
Not open for further replies.

litsz02

Technical User
Aug 26, 2004
45
US
Hi all,

I've been searching and I cannot find a reasonable answer. it seems very basic solution, however I just cant seem to find it.

Basically what i'm trying to do is I have a table and I need to check a column Accountnumber and if it contains an L in it, update another column named (Desc) with a description. if it contains a O, update Desc with a different description, and so on.

I cannot for the life of me figure out what string function can do this....

My psudo code looks like this:
Setup cursor to move through the table
If accountnumber contains "L" then
Update DESC with "Life Insurance"
Else if Accountnumber contains "O"
Update Desc with "Other"
Else if no match
Update Desc with "NONE"

Can someone help me out here?! Im still a newbie at code. maybe i'm looking at this wrong.
 
UPDATE myTable SET description = CASE
WHEN charIndex('L',accountNumber) > 0 THEN 'some text'
WHEN charIndex('O',accountNumber) > 0 THEN 'other text'
END

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Worked like a charm thanks so much!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top