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

SEARCHING FOR A TEXT INSIDE AN STRING

Status
Not open for further replies.

Raul2005

Programmer
Sep 23, 2005
44
US
I need some help to:

ID USERNAME MESSage
1 nrj hello(nrj)there is a..
2 pqt hola(nrj) today we had
3 nrj Try one more(nrj)time


I need the following resul

ID USERNAME MESSage STATUS
1 nrj hello(nrj)there SENT
2 pqt hola(nrj) today we RECEIVED
3 nrj Try one more(nrj) SENT

As you can see I need to look inside the message string for the value I have in field USERNAME Ineed to compare and if inside the message string I found a value like the USERNAME I need to display another field with tthe status set to SENT in other case it will be se to Received.

I will appreciate any help

Raul
 
This is untested, but should solve your problem

Code:
Select ID,
       UserName,
       Message,
       Case When CharIndex(UserName, Message) > 0
            Then 'Sent'
            Else 'Received'
            End As Status
From   Table

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks gmmastros.
However the result is returning "Received" for everyone I believe there is a problem with the parentesis around.

IT SHOULD RETURN

ID USERNAME MESSage STATUS
1 nrj hello(nrj)there SENT
2 pqt hola(nrj) today we RECEIVED
3 nrj Try one more(nrj) SENT

IT IS RETURNING

ID USERNAME MESSage STATUS
1 nrj hello(nrj)there RECEIVED
2 pqt hola(nrj) today we RECEIVED
3 nrj Try one more(nrj) RECEIVED


Thanks
 
I solved like this>>>>>>

Select ID,
UserName,
Message,
Case When CharIndex('('+rtrim(UserName)+')', Message) > 0
Then 'Sent'
Else 'Received'
End As Status
From ATEST
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top