Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MS SQL substring a character

Posted on 2008-10-07
3
Medium Priority
?
592 Views
Last Modified: 2010-04-21
I viewed searched and found one of the questions that pertains to my issue "MS SQL substring a character"  The response did not work for me however i was hoping to get more assistance with a similar issue.

I am looking to pull the characters that happen on the left side of the first ':' for instance i could have data that looks like 12:31:01 or 13:20 or 1:00 or 3:00:09:00

In all of these cases i would like to pull out and use the 12,13,1, and 3

The code i attempted to modify was

substring(ltrim(rtrim(field)), 1, Charindex('$', ltrim(rtrim(field)))

I modified it to look like this:

substring(ltrim(rtrim([Time])), 1, Charindex(':', ltrim(rtrim([time])))

in which i received an error invalid or missing Expression.
0
Comment
Question by:JPLLaf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22664708
Try this:
SELECT LEFT('12:31:01', CHARINDEX(':', '12:31:01')-1)

Open in new window

0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22664727
Or simply this if you know there is at least one number up to max of 2 before the first ':'.
SELECT REPLACE(LEFT(LTrim(RTrim([Time])), 2), ':', '')

Open in new window

0
 

Author Closing Comment

by:JPLLaf
ID: 31504031
The second solution works great, for some reason the first one caused errors in previous ddate time formulas in my View.  Awesome work thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 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