Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1545
  • Last Modified:

cast mySQL string to double

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
portlight
Asked:
portlight
  • 2
1 Solution
 
5teveoCommented:
Try

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

or whatever size you need
0
 
portlightAuthor Commented:
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
 
arnoldCommented:
First make sure the extraction gets you the value out.
Can you post the string from which you want the data extracted?
0
 
5teveoCommented:
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now