Solved

cast mySQL string to double

Posted on 2013-12-13
4
1,369 Views
Last Modified: 2013-12-17
I am having to pull a cost from a string....
 substr(l.details, instr(l.details , ':' ) +1)AS charge,

This works for doing the calculations correctly, HOWEVER when I to print the value is prints as an 'object'  not a string.

I have tried cast and convert....how can i get this above code to print the actual string out
0
Comment
Question by:portlight
[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
4 Comments
 
LVL 8

Expert Comment

by:5teveo
ID: 39717899
Try

Cast (substr(l.details, instr(l.details , ':' ) +1), varchar(5))

or whatever size you need
0
 

Author Comment

by:portlight
ID: 39717915
That gave me an error at the ,

I did cast to a double but it created it as a zero.

The value I am looking to see is .70
0
 
LVL 79

Expert Comment

by:arnold
ID: 39719475
First make sure the extraction gets you the value out.
Can you post the string from which you want the data extracted?
0
 
LVL 8

Accepted Solution

by:
5teveo earned 500 total points
ID: 39722391
Declare @vCostString as varchar(50)

Set @vCostString = 'This is the cost :1.07';

Select Cast(substring(@vCostString, charindex(':',@vCostString) +1, 4) as varchar(5))

I guessed at lenght of 4 which is 1.07 value lenght.

We need a string example to make formula as you expect

Maybe this sample select is enough to get you started
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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.

626 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