Solved

cast mySQL string to double

Posted on 2013-12-13
4
1,284 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 77

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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