Advertisement

05.29.2008 at 09:51AM PDT, ID: 23442097
[x]
Attachment Details

How do I trim 5 characters from a string

Asked by indy500fan in SQL Server 2005

Tags: T-SQL (SQL Server 2005)

Friends,

I have the following part of my qry:

Seconds=case when ((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000)-((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000))/60.0000))*60.0000))<10
then '0' + cast(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000)-((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000))/60.0000))*60.0000))as varchar)
else cast(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000)-((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000))/60.0000))*60.0000))as varchar) end,

I am using it to return the seconds part of a time.

Right now, Seconds would be 27.8508 for a passing time value of 475478508.

Unfortunately, I only want the 27 part of time time.  Since the return value is as string, can't I somehow TRIM it from the "." on?  Or is there a better way.

Below, you will find the entire qry.

Thanks in advance!

Best Regards,
EricStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
select t.LeaderLap,
Hours=case when (passingtime*.0001)/3600 < 10 
then '0' + cast(floor((passingtime*.0001)/3600) as varchar) 
else cast(floor((passingtime*.0001)/3600) as varchar) end,
Minutes=case when (floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600))*3600))/60)) <10 
then '0' + cast((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600))*3600))/60))as varchar) 
else cast((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600))*3600))/60))as varchar) end,
Seconds=case when ((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000)-((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000))/60.0000))*60.0000))<10 
then '0' + cast(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000)-((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000))/60.0000))*60.0000))as varchar)
else cast(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000)-((floor(((passingtime*.0001)-((floor((passingtime*.0001)/3600.0000))*3600.0000))/60.0000))*60.0000))as varchar) end,
SecondsTrimed=TRIM(Seconds '.')
FROM passings t
Where
leaderlap>=0
AND decoderid=100
AND deleted=0
AND RunID = (SELECT RunID FROM Runs WHERE Preamble = 'R.I')
 and t.PassingID = ( select min(i.passingid) from passings i where i.leaderLap = t.LeaderLap) 
Order By t.LeaderLap asc
 
Loading Advertisement...
 
[+][-]05.29.2008 at 09:55AM PDT, ID: 21670987

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 09:59AM PDT, ID: 21671026

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 10:03AM PDT, ID: 21671057

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 10:05AM PDT, ID: 21671082

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 10:07AM PDT, ID: 21671095

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 10:12AM PDT, ID: 21671152

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.29.2008 at 10:16AM PDT, ID: 21671182

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Tags: T-SQL (SQL Server 2005)
Sign Up Now!
Solution Provided By: Thomasian
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.29.2008 at 10:18AM PDT, ID: 21671204

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628