Solved

How to find value in text

Posted on 2013-06-03
3
304 Views
Last Modified: 2013-06-04
I am not sure which function to use to find the text I am looking for.  I thought it was the CHARINDEX but it is not returning the desired results.  I am looking for the name which starts in the same location every time but can be different lengths.  The end of the name is designated by a space.  I am using the following logic:

SUBSTRING(MASTER24_HISTORY.MRHISTORY,21,CHARINDEX(' ', LEFT(MASTER24_HISTORY.mrHISTORY,22)))

However it is pulling more than just the name.  Any idea why?
0
Comment
Question by:Gary Harper
3 Comments
 
LVL 45

Accepted Solution

by:
Kdo earned 400 total points
ID: 39217553
Hi GHarper,

It looks like you're mixing techniques.  :)

First limit the variable (chop off the bit to the right:
  LEFT (item, charindex (item, ' ', start))

Then grab the desired portion:
  SUBSTRING (LEFT (item, charindex (item, ' ', start), start, limit)

Limit is the size of the variable.  You can compute a value, but this is easier to code.


Good Luck,
Kent
0
 
LVL 39

Expert Comment

by:lcohan
ID: 39219448
I suggest you look for PATINDEX ( '%pattern%' , expression ) to find the possition of the ' ' - or space char in your string and build/calculate your SUBSTRING based on that.
0
 

Author Comment

by:Gary Harper
ID: 39219538
kdo pointed me in the right direction.  I ended up using

SUBSTRING(item,21,CHARINDEX(' ',item,21) - 21) as 'Username'
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now