Link to home
Start Free TrialLog in
Avatar of Jimbo99999
Jimbo99999Flag for United States of America

asked on

VB.Net - SQL Query Getting End of Field Data

Good Day Experts!

I have an intriguing request that seems possible to achieve but I am not quite sure how to achieve it.

I have a field in a SQL table called Notes.  In Notes, there may or may not be information pertaining to a Department.  If appearing the Department will vary in length.  Also. there will be varying amount of data in front of the Department.  Here is how it will appear in the data:

Notes:
<Variable amount of text>Department(1)
<Variable amount of text>Department(TG)
<Variable amount of text>Department(456)

I was thinking to work from the end since I cannot be 100% positive the word Department won't appear in the <Variable amount of text>.  

How can I work from the end back until the D in Department?

Thanks,
jimbo999999
Avatar of Phillip Burton
Phillip Burton

As it is vb.net you are using, can you use the InstrRev function?
Avatar of Vitor Montalvão
What is the data type of Notes?
Avatar of Jimbo99999

ASKER

I tried it in the query and I receive feedback indicating InStrRev is not a recognized function name.
SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
select
   right( [Notefield] ,charindex('D',reverse( [NoteField] )))
from Notes

{+edit}
didn't know the field name so I used [Notefield]
Vitor: Thanks for replying. I was sitting on the question typing and did not refresh to see your contribution. I apologize for any confusion.

The DataType for Notes is varchar.

Thanks,
jimbo99999
Good. I was afraid that it would be a TEXT field but if it's Varchar you can perform search in the field with the above functions.
By the way, do you want to return the department name or doesn't matter and you only want to return the rows that has DEPARTMENT in the Notes?
If so, then you can use the '%' wildcard:
SELECT *
FROM TableName
WHERE Notes LIKE '%department%'

Open in new window

I am already sitting on the record and have the Notes field.  I am trying to parse it from the field like what Paul is suggesting.  I am trying it now.