Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cast mySQL string to double

Posted on 2013-12-13
4
Medium Priority
?
1,419 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 2000 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

721 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