Solved

MS SQL substring a character

Posted on 2008-10-07
3
585 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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