Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

cast mySQL string to double

Posted on 2013-12-13
4
Medium Priority
?
1,470 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
  • 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 80

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this article, we’ll look at how to deploy ProxySQL.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

972 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